Error: "Cout" was not declared in this scope

Hi!
While compiling the below code I got the 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
28
29
30
31
  #include <iostream>
int main ()
{
int age1, age2, age3, age4, age5, age6, age7, age8, age9, age10;
int TotalAge;
int AverageAge;
cout<<"Please Enter the age of student 1:" //Cout is not declared in this scope.
cin >> age1;
cout<<"Please Enter the age of student 2:"
cin >> age2;
cout<<"Please Enter the age of student 3:"
cin >> age3;
cout<<"Please Enter the age of student 4:"
cin >> age4;
cout<<"Please Enter the age of student 5:"
cin >> age5;
cout<<"Please Enter the age of student 6:"
cin >> age6;
cout<<"Please Enter the age of student 7:"
cin >> age7;
cout<<"Please Enter the age of student 8:"
cin >> age8;
cout<<"Please Enter the age of student 9:"
cin >> age9;
cout<<"Please Enter the age of student 10:"
cin >> age10;
TotalAge = age1+age2+age3+age4+age5+age6+age7+age8+age9+age10;
AverageAge = TotalAge / 10;
cout<< "The average age of students is:"
<< AverageAge;
}


Kindly help me with that.
cout is in the std namespace.

Options

1) Replace cout with std::cout
2) Put using std::cout; at the start of main()
3) Put using namepsace std; after the include. DON'T DO THIS. THIS IS BAD. DON'T DO THIS.

Where did you get this code? This would have worked on some compilers a long time ago.
Last edited on
Another option is to put using std::cout; after the includes instead of at the start of main().

After you get the code working, see if you can do it without all that age variables. You will need a loop.
Topic archived. No new replies allowed.