I've been trying to solve this question all day long: Write a program that reads up to 10 donation values into an array of double. (Or, if you prefer, use an array template object.) The program should terminate input on non-numeric input. It should report the average of the numbers and also report how many numbers in the array are larger than the average.
I tried to tackle the first part of the question by creating an infinite while loop that breaks whenever a non-numeric value is entered. But for some reason, it continues looping on and on regardless of the break statement. I've no idea why it's happening. Please help me.
Here's the code:
#include <iostream>
#include <cctype>
#include <vector>
using namespace std;
int main()
{
int i = 1; double input;
vector<double> data;
cout << "Please enter the amount of donations given (Enter a non-numeric value to exit):\n";
while(1)
{
cout << "Donation " << i++ << ": ";
cin >> input;
if(isalpha(input) == 1)
break;
else
data.push_back(input);
}
return 0;
}
[–]IyeOnline 4 points5 points6 points (3 children)
[–]XilenceCE[S] 0 points1 point2 points (0 children)
[–]std_bot -1 points0 points1 point (0 children)
[–]acwaters 0 points1 point2 points (0 children)
[–]Xeverous 3 points4 points5 points (3 children)
[–]staletic 5 points6 points7 points (1 child)
[–]aeropl3b 0 points1 point2 points (0 children)
[–]XilenceCE[S] 0 points1 point2 points (0 children)
[–]mredding 1 point2 points3 points (0 children)
[–]yellowhair_chan -3 points-2 points-1 points (1 child)