So I've debugged this program a few times and it has worked just fine, until now for some reason.. When I run it now and when I've written down 10 "donations" I get the following error message...
For information on how your proghram can cause assertion failure, see the Visual C++
documentation on asserts
(Press Retry to debug the application)
What's causing this? This also happens when I type a letter instead of an digit.. (The program is supposed to be terminated when the user input letters..)
Has it anything to do with (isdigit(donation[i])) ?
#include "stdafx.h"
#include <iostream>
#include <cctype>
int main()
{
usingnamespace std;
double donation[10];
double sum = 0;
double average = 0;
int higerthanaverage = 0;
int i = 0;
int o = 0;
cout << "Please enter your 10 donations to Childrens Hospital: " << endl;
while ( i < 10 || (isdigit(donation[i]))) // is this causing the problem?
{
cin >> donation[i];
sum += donation[i];
i++;
}
average = sum / 10;
while ( o <= 10)
{
if (donation[o] > average)
higerthanaverage++;
o++;
}
cout << "Total donations from you are = " << sum << ", with an average of = " << average << endl;
cout << "Donation higher than average: " << higerthanaverage;
cin.get();
cin.get();
return 0;
}