0% found this document useful (0 votes)
30 views

Labs CS-201 Week # 2 Lab 1 Problem Statement:: #Include Using Namespace STD

The document describes a coding problem to calculate the average age of 10 students. It outlines declaring 10 integer variables to store each student's age and prompting the user to input the age of each student. It then shows the calculation of totaling all the ages and dividing by 10 to find the average age. The solution provided implements this by declaring the necessary variables, using cin to input each age, calculating the total and average, and outputting the result.

Uploaded by

Shahid Irfani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Labs CS-201 Week # 2 Lab 1 Problem Statement:: #Include Using Namespace STD

The document describes a coding problem to calculate the average age of 10 students. It outlines declaring 10 integer variables to store each student's age and prompting the user to input the age of each student. It then shows the calculation of totaling all the ages and dividing by 10 to find the average age. The solution provided implements this by declaring the necessary variables, using cin to input each age, calculating the total and average, and outputting the result.

Uploaded by

Shahid Irfani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Labs CS-201

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.”

 We need 10 variables of int type to calculate the average age.


int age1, age2, age3, age4, age5, age6, age7, age8, age9, age10;

 “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 ;

AverageAge = TotalAge / 10;

Solution:

#include<iostream>

using namespace std;

main() {

int age1 = 0, age2 = 0, age3 = 0, age4 = 0, age5 = 0, age6 = 0, age7 = 0, age8 = 0,


age9 = 0, age10 = 0;

int TotalAge = 0, AverageAge = 0;

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;

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;

//Display the result (average age)

cout<<"Average of students is: "<<AverageAge;

You might also like