Yet another compile error

I am trying to use this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
int main()
{
cout << "How old is the first student?";
cin >> age1;
cout << "How old is the second student?";
cin >> age2;
cout << "3rd?";
cin >> age3;
cout << "4th?";
cin >> age4;
cout << "5th?";
cin age5;
totalAge = age1 + age2 + age3 + age4 + age5;
averageAge = totalAge / 5;
cout << "The average age is: " averageAge;
return 0;
}

And I get this error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Compiling: C:\Users\Rex\Desktop\Test.cpp
C:\Users\Rex\Desktop\Test.cpp: In function 'int main()':
C:\Users\Rex\Desktop\Test.cpp:6: error: 'age1' was not declared in this scope
C:\Users\Rex\Desktop\Test.cpp:8: error: 'age2' was not declared in this scope
C:\Users\Rex\Desktop\Test.cpp:10: error: 'age3' was not declared in this scope
C:\Users\Rex\Desktop\Test.cpp:12: error: 'age4' was not declared in this scope
C:\Users\Rex\Desktop\Test.cpp:14: error: expected ';' before 'age5'
C:\Users\Rex\Desktop\Test.cpp:15: error: 'totalAge' was not declared in this scope
C:\Users\Rex\Desktop\Test.cpp:15: error: 'age5' was not declared in this scope
C:\Users\Rex\Desktop\Test.cpp:16: error: 'averageAge' was not declared in this scope
C:\Users\Rex\Desktop\Test.cpp:17: error: expected ';' before 'averageAge'
Process terminated with status 1 (0 minutes, 0 seconds)
9 errors, 0 warnings
 

I am not sure if I am thinking of C code for this, because I did have a look at some source code earlier that was C.
You forgot to declare the variables (pretty much what the error messages say).
-_- Omg I feel like a retard. Thanks for the help.
Last edited on
Topic archived. No new replies allowed.