#include <iostream>
#include <vector>
usingnamespace std;
int main()
{
vector<double> temps;
for (double inp_temp; cin >> inp_temp;)
{
temps.push_back(inp_temp);
}
double sum = 0, high_temp = 0, low_temp = 0;
for (int x : temps)
{
if (x < low_temp) low_temp = x;
if (x > high_temp) high_temp = x;
sum += x;
}
char test;
cout << "High: " << high_temp << endl;
cout << "Low: " << low_temp << endl;
cout << "Sum: " << sum << endl;
cout << "Average: " << sum/temps.size() << endl;
cin >> test;
cout << "The test char =[" << test << "]" << endl;
return 0;
}
The program does not stop to let me input char test. I tried changing endl to '\n', however it did not help. The last cout always prints "The test char =[]".
How to fix that?
To break out of the loop starting on line 9, I figure you must be putting in something that will put cin into a fail state, otherwise you'd keep on pushing new values into temps. You will need to call cin.clear() at some point before you try getting more input.
Thank you very much booradley60.
Indeed, I forgot that while exiting the first for loop I put cin in a fail state, so that it discards everything.
Inserting cin.clear() and cin.ignore() before cin >> test helped!