简体   繁体   English

输入<> 0时“执行”循环

[英]“do” loop while entry <> 0

Write an application that keeps inputting an integer from the user until zero is entered. 编写一个应用程序,该应用程序不断从用户输入整数,直到输入零为止。
The program will calculate and display the average of the numbers, and display the largest and smallest of the numbers. 该程序将计算并显示数字的平均值,并显示数字的最大和最小。
Zero is not to be included in the average, largest or smallest printouts. 零,最大或最小打印输出中不包括零。

I tried it and got this far: 我试了一下,走了这么远:

#include <iostream>
using namespace std;

int main () {
    string str;
    do {
        cout << "Enter text: ";
        getline (cin,str);
        cout << "You entered: " << str;
        cout <<str + str;
    } while (str != "0");
}

How do I get the average of the numbers with only one variable and how do I get the biggest and smallest number? 如何仅使用一个变量来获得数字的平均值,以及如何获得最大和最小的数字?

you will have to define couple of other variables to track the smallest and largest values. 您将必须定义几个其他变量来跟踪最小和最大值。 you have to check whether a new number entered by the user is small than the earlier smallest value and whether the new number is larger than the earlier largest value. 您必须检查用户输入的新数字是否小于先前的最小值,以及新数字是否大于先前的最大值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM