Debug Assertion Failed

Hi all!

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...

Debug Asserion Failed

Program: ...Programming exercises 6.2\Debug\Programming exercises 6.2.exe
File f:\dd\vctools\crt_bld\self_x86\crt\src\istype.c
Line: 56

Expression: (unsigned)(c+1) <= 256

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])) ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "stdafx.h"
#include <iostream>
#include <cctype>

int main()
{
	using namespace 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;
}


Any ideas? Thanks
Last edited on
Topic archived. No new replies allowed.