[学习笔记]C++17学习第11天
```# include <iostream>
# include <iomanip>
// c++17
using namespace std;
int main()
{
size_t count {};
cout << "How many heights will you enter? ";
cin >> count;
int height;
for(size_t i{}; i!= count;)
{
cout << "Enter a height: ";
cin >> height;
if (height>0)
++i;
else
cout << "A height must be positive -- try again." << endl;
}
int total {};
for (auto x : height)
{
total += x;
}
cout << fixed << setprecision(2);
cout << "The average height is " << static_cast<double>(total)/count << endl;
}
```
```
# include <iostream>
# include <array>
// c++17
using namespace std;
int main()
{
array<double, 4> these {1.0,2.0,3.0,4.0};
array<double, 4> those {1.0, 2.0, 3.0, 4.0};
array<double, 4> them;
them.fill(3.1415926);
cout << "Them size is " << them.size() << endl;
if (these == those )
cout << "these and those are equal." << endl;
}
```
为啥教材上都是用cout,不用print 呢? 不错不错
不错不错 Good,持之以恒,必成大器。 cdl279 发表于 2021-5-27 08:47
为啥教材上都是用cout,不用print 呢?
因为不同的语言有不同的规则,就像不同的交通工具有不同的运作轨道一样,虽然都是将你从一个地方运输到另一个地方,但是方法方式不太一样而已 谢谢楼主分享,支持一下。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。 不知道学编程怎么持续下去
页:
[1]
2