Help with array code

Hey, I am new to this site and am seeking help with fixing this code. It's supposed to take user input to replace specific parts of an array of size 10. Putting an if statement to make it so that the user wouldn't be able to put index numbers above 9 or below 0 doesn't seem to make the do-while statement end, and was wondering where I went wrong. Any help would be greatly appreciated!

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
#include <iostream>
using namespace std;
int main()
{
	int myData[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, i, v; 
	for(int c = 0; c < 10; c = c+1) 
		do
		{
			for(int c = 0; c < 10; c = c+1)
			{
				cout << myData[c] << " ";
			}
			cout << endl;
			cout << "Input index: ";
			cin >> i;			
			cout << "Input value: ";
			cin >> v;
			if((i < 10) or (i > -1))
			{
				myData[i] = v;
			}
			else
				cout << "Index out of range. Exit";
		}
		while((i < 10) or (i > -1));
	return 0;
}
Hello SonnyTedesco,

Welcome to the forum.

You have two problems with your code that makes me wonder if you compiled the program to reveal these.

In lines 18 and 25 the "or" is not a keyword and will not work the way you are thinking. In the case of "or" the proper symbol is "||" and for "and" it is "&&". Also the inner () are not really needed.

In lines 6 and 9 the "c = c + 1" will work, but this i more commonly written as "c++" or "++c".

This is what I see, but I still want to test the program.

Hope that helps,

Andy
Thank you for the advice. I modified lines 18 and 25 to have the actual symbol for OR. When looking at it further, I realized how silly i was for putting the OR there instead of AND to to basically say IF(-1<i<10), and now the code seems to be working just fine. Thanks!
Topic archived. No new replies allowed.