ex3_10.cpp
来自「Beginning Visual C++ 6源码。Wrox。」· C++ 代码 · 共 35 行
CPP
35 行
// EX3_10.CPP
// Using an infinite for loop to compute an average
#include <iostream>
using namespace std;
int main()
{
double value = 0.0; // Value entered stored here
double sum = 0.0; // Total of values accumulated here
int i = 0; // Count of number of values
char indicator = 'n'; // Continue or not?
for(;;) // Infinite loop
{
cout << endl
<< "Enter a value: ";
cin >> value; // Read a value
++i; // Increment count
sum += value; // Add current input to total
cout << endl
<< "Do you want to enter another value (enter n to end)? ";
cin >> indicator; // Read indicator
if ((indicator == 'n') || (indicator == 'N'))
break; // Exit from loop
}
cout << endl
<< "The average of the " << i
<< " values you entered is " << sum/i << "."
<< endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?