loop iteration

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
#include "StdAfx.h"
#include <iostream>
using namespace std;


int main()
{
    
	int user;    
	do{
		cout << "Please enter any number other than 5: \t";
		cin >> user;
	} while (user != 5 );

		cout << "Hey! you were'nt suppose to enter 5! .\n";
	for (int i = 0; i <= 10; i++)
		
		if (user[i] >= 10){
		
			cout << "wow you are more patient than i am: ";
		}

	
	
	return 0;
}

my problem is that i want to loop the user for 10 iterations if the user still hasn't entered 5 will tell the user "Wow, you're more patient then I am, you win." and exit.
but i am really stuck it keep saying
Error	1	error C2109: subscript requires array or pointer type	c:\users\ozone\documents\visual studio 2010\projects\ozone\ozone\ozone.cpp	20
	2	IntelliSense: expression must have pointer-to-object type	c:\users\ozone\documents\visual studio 2010\projects\ozone\ozone\ozone.cpp	20
thanks
warm regards
closed account (zb0S216C)
user is but a single int, not an array of ints[1].

References:
[1] http://www.cplusplus.com/doc/tutorial/arrays/


Wazzak
hey man am still a newbie i dont seem to understand where i am wrong. just need some correction.
ozone,

consider this to understand it better:
int MyVariable;

What is MyVariable and how is it stored in memory of your computer?

well int is 4 Bytes wide. (on some OS-es it is 2 bytes however)

so your int is stored into a 4 Bytes block inside a memory (hipoteticaly)

How do you write some data into that block of memory?

you will type this:

MyVariable = 541;

and how do you read from that block of memory?

you type:

MyVariable;


Now consider this problem:

You need 10 ints not only one:

How will you alocate a block of memory for 10 int's ? (on the stack)

int MyVariable[10];

Now you have a block of 10 * 4 Bytes = 40 Bytes wide block

How do you input some data into that block?

you type:
1
2
MyVariable[0] = 4;     // write into first int
MyVariable[1] = 445; // write into second int 

etc....

as you see counting goes from zerro not from 1 :D

And how do you read from that block of memory?

MyVariable[0]; // read first int.


Now by having this super knowelege, you are able to solve your problem on your own! :D
@codekiddy you are the bomb. thanks alot. you just relieve me of ma stress :D
Topic archived. No new replies allowed.