7302人加入学习
(18人评价)
C++编程系列 第一季编程基础

制作于2018年2月7日

价格 免费

    不用if,break的方法

    float number = 1, total = 0;
    while (number > 0) {
        cout << "请输入数字:";
        cin >> number;
        total += number;
        cout << "当前输入所有数字的和为:" << total << endl;
    }

[展开全文]

用了另外一个方法

        int total=0;
        int a;
        do
        {
            cout << "请输出一个数字:";
            cin >> a;
            total += a;
            cout << "当前数字总和为:" << total << endl;
        } while (a != 0);

 

[展开全文]

while(true){

 

}

死循环

 

 

跳出xun'h

while(){

if(条件){

break;

}

}

[展开全文]

total = 0; float num; do { cout << "Please enter a number:"; cin >> num; total += num; cout << total << endl; } while (num != 0);

[展开全文]

7,编写一个程序,让用户可以持续输入数字,每次输入数字,报告当前所有输入的和。当用户输入0的时候,程序结束。

siki:

    float total = 0;
    while (true)
    {
        cout << "请输入一个数字:";
        float number;
        cin >> number;

        if (number == 0)
        {
            break;
        }

        total += number;
        cout << "当前所有输入的和为:" << total << endl;
    }

 

自写:

    bool execute = true;
    float totalNum = 0;
    while (execute)
    {
        float temp;
        cout << "请输入一个数字:";
        cin >> temp;
        if (temp == 0)
        {
            execute = false;
        }
        totalNum += temp;
        cout << "当前和为:" << totalNum << endl;
    }

[展开全文]

授课教师

SiKi学院老师

课程特色

下载资料(1)
视频(58)