CS201 Lab Exercise
CS201 Lab Exercise
Problem Statement:
“Calculate the average age of a class of ten students. Prompt the user to enter the age of each student.”
“Prompt the user to enter the age of each student” this requires cin>> statement.
For example:
cin>> age1;
Average can be calculated by doing addition of 10 variables and dividing sum with 10.
TotalAge = age1 + age2 + age3 + age4 + age5 + age6 + age7 + age8 +age9 + age10 ;
Solution:
#include<iostream>
main() {
int age=0;
for(int i = 1;i<=10;i++)
cin>>age;
TotalAge += age;
AverageAge = TotalAge/10;