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.
我试过了,走到了这一步:
#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");
}
如何获得只有一个变量的数字的平均值,以及如何获得最大和最小的数字?
最佳答案
您将必须定义几个其他变量来跟踪最小值和最大值。你必须检查用户输入的新数字是否小于先前的最小值,以及新数字是否大于先前的最大值。
关于c++ - "do"循环而条目 <> 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29136157/