吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1802|回复: 12
收起左侧

[学习记录] [学习笔记]C++17学习第11天

[复制链接]
mdl2999_52pj 发表于 2021-5-27 08:16
# 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[count];

    for(size_t i{}; i!= count;)
    {
        cout << "Enter a height: ";

        cin >> height[i]; 
        if (height[i]>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;
}


001.png

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
huangyiyi + 1 + 1 给爱学习的人加1分

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| mdl2999_52pj 发表于 2021-5-27 08:29
# 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;
}



002.png
cdl279 发表于 2021-5-27 08:47
头像被屏蔽
tlf 发表于 2021-5-27 08:51
q185335680 发表于 2021-5-27 09:00
不错不错
shinnair0121 发表于 2021-5-27 09:15

不错不错
Arsage 发表于 2021-5-27 09:50
Good,持之以恒,必成大器。
msugry 发表于 2021-5-27 10:17
cdl279 发表于 2021-5-27 08:47
为啥教材上都是用cout,不用print 呢?

因为不同的语言有不同的规则,就像不同的交通工具有不同的运作轨道一样,虽然都是将你从一个地方运输到另一个地方,但是方法方式不太一样而已
liangshen95 发表于 2021-5-27 10:24
谢谢楼主分享,支持一下。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
teenage1997 发表于 2021-5-27 11:33
不知道学编程怎么持续下去
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-20 08:52

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表