Hello I\'m new at this as well as confuse how do I program this: Do you have any
ID: 3623423 • Letter: H
Question
Hello I'm new at this as well as confuse how do I program this: Do you have any sample? Thanks
FUNCTION
write a program to calculate the average of the class by following steps:
1. ask the user to input students in the class (guess any number)
2. use random function to generate the score (between 0 and 100) for each student and calculate the total of the scores by using while loop.
3. define a function "double average(int, int)" to calculate the class average
4. in main function call average function and display the average of the class
Explanation / Answer
please rate - thanks
#include <iostream>
#include <ctime>
#include <cstdlib>
double average(double,double);
using namespace std;
int main()
{int num,i,sum=0,students;
srand(time(0));
cout<<"How many students in the class: ";
cin>>students;
i=0;
cout<<"The grades are: ";
while(i<students)
{num=rand()%101;
cout<<num<<" ";
sum+=num;
i++;
}
cout<<" The class average is :"<<average(sum,students)<<endl;
system("pause");
return 0;
}
double average(double sum,double students)
{return sum/students;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.