Labs CS-201 Week # 2 Lab 1 Problem Statement:: #Include Using Namespace STD
Labs CS-201 Week # 2 Lab 1 Problem Statement:: #Include Using Namespace STD
Week # 2
Lab 1
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() {
cin>>age2;
cin>>age3;
cin>>age4;
cin>>age5;
cin>>age6;
cin>>age7;
cin>>age8;
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;