Hi some questions about for loop

Hi,

I have got some questions about "For Loop".

I was working on my program in which I made a class of student.

I wanted to have a "for loop" in it as :
-------------------------------------------------

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
main()

{

char grade;
int i;


for( i=0;i<5;i++)

{
cout<<"pls enter the grade of student";

cin>>"i"

grade=cin.get(i)

}

system("pause");

}

-----------------------------------------------

I have just made this program to test,I want user to input the grade of the student and that value should be stored in "i". Later that value in "i" that user entered must be stored in the variable "grade".

But when I compile this program I get an error messege.
I wanted to know what mistake am I making ?

Also have I declared the variable for "i" correctly?

Thanks
Last edited on
This cin>>"i" should be like this cin>>i. Why do you want to store the value in i, then transfer it to grade ?

You should use a syntax either:
cin >> i;
or
cin.get(i);
or
i = cin.get();

Not the one you use. The same stands for grade also of course. The compiler does not know what of these overloaded versions you want.

Note though that the first one works for doubles also the other one only for chars.

You can check:
http://www.cplusplus.com/reference/iostream/istream/get/
Last edited on
Topic archived. No new replies allowed.