can't find error.

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
#include<stdio.h>

int getNum(int i){
	static int person[10];
	printf("Enter Pancake count for person %d: ", i+1);
	scanf("%d", &person[i]);
	return person[i];
}

int main(void){
	int i, x, temp, pancake[10];
	for(i = 0; i < 10; i++){
		pancake[i] = getNum(i);
	}

	for(i = 10; i > 0; i++){
		for(x = 0; x < i-1; x++){
			if(pancake[x] < pancake[x+1]){ // compiler points to this line, dunno why.
				temp = pancake[x];
				pancake[x] = pancake[x+1];
				pancake[x+1] = temp;
			}
		}
	}
	printf("\n\n%d", pancake[0]);
	scanf("%d", &x);
}


basically it asks for the number of pancakes one person ate up to the 10th person and sorts them. i got the problem from one thread here. :P

the compiler says 'Unhandled Exception'. it does compile, but as soon as i finish all the input up to the 10th array member, the error shows. i tried using small numbers because maybe they're too much for int. still the same.

i'm using VS 2010 on Windows 7.

i don't know if it's the best way of doing it but i try to add variation and integrate what i have learned for every problem instead of just solving the problem for the sake of solving it.
Last edited on
In this line:
for(i = 10; i > 0; i++)

Are you meaning to decrement there? Because that's what it looks like to me. It seems like you want i-- instead of i++.
thanks a lot. lol that was embarrassing...

SOLVED
Topic archived. No new replies allowed.