Following along a tutorial I entered code for a person to enter the age of five students.
Then, the program is supposed to divide the five ages and display the result.
It allows me to enter the ages, but as soon as I hit enter after inputting the fifth age, the window closes.
I have looked over the code, can't find anything wrong. Can someone help please.
/* This program calculates the average age of a class of
five students after prompting the user to enter the age
of each student*/
#include <iostream.h>
main()
{
// declaration of variables, the age will be in whole numbers//
int age1, age2, age3, age4, age5;
int TotalAge, AverageAge;
//Take ages of the students from the user//
cout << "Please enter the age of student 1:";
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;
//Calculate the total age and average age//
TotalAge = age1 + age2 + age3 + age4 + age5;
AverageAge = TotalAge / 5;
//Display the result (average age)//
cout << "Average age of class is:" <<AverageAge;
}
Also, how can someone (namely myself) tell if the code is written in C or C++?
Any pointers on the look, ie: the structure of my coding.