c++ - "do"循环而条目 <> 0

标签 c++

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/

相关文章:

c++ - 初始化时将函数作为构造函数参数传递给基类构造函数

c++ - BOOST::thread worker 同步,C++ 和 OpenCV

c++ - 如何在使用 Eclipse CDT 进行调试时向 gdb 提示符输入命令?

c++ - 防止内存泄漏(具体情况)

c++ - 无法进行混合工作

c++ - 为什么 istream::get 将 failbit 和 eofbit 设置在一起?

c++ - WSAWaitForMultipleEvents 和 NetworkEvents

c++ - 以变​​化的间隔生成随机整数

c++ - 不使用跳转语句的结构化解决方案

c++ - 重构以下两个C++方法,移出重复代码