Code Error!

So, I began writing this code in Visual Basic and I wanted a simpler way to loop this. I might be over thinking here, but I did get an error and I just wanted some opinions and suggestions. By the way, this isn't a complete program yet. Just trying things out to see what works as I go.

*Note, totally new to this website. Not quite sure how to post with code format yet.

ERROR MESSAGE: Run-Time Check Failure #2 - Stack around the variable 'scr' was corrupted.

1
2
3
4
5
6
7
8
9
10
11
	for (int x = 1; x <= 5; x++)
		{
		cout << "Score number " << x << ":\t";
		cin >> scr[x];
		while ((scr[x] > 10.00) || (scr[x] < 0.00))
		{
			cout << "\nError: Number must be in decimal form, between 0.00 and 10.00" << endl;
			cin >> scr[x];
		}
	}


Last edited on
@3 float scr[5];
@18 for (int x = 1; x <= 5; x++)
@21 cin >> scr[x]

The loop counter, x, starts from 1 and goes till 5 (inclusive). So in the above cin statement (at 21) array scr is being indexed from scr[1]..scr[5]. But the memory for scr is from scr[0]...scr[4]. This is out of boundary access.
Oh darn it! Thanks for letting me know. I changed it around to get it to do the right thing without the error!
Topic archived. No new replies allowed.