In: Computer Science
A professor wants to do some research on students who use different kinds of computers. They are curious if there is any difference in average test scores between , for instance, Mac users and Windows users. Write a program to help with this, that behaves as follows.
Here is the code, I have tried to be as descriptive as possible :
#include <bits/stdc++.h>
using namespace std;
float sumW = 0, sumO = 0, sumM = 0;
// These
values are the accumulators for each type of computer.
int countW = 0, countO = 0, countM = 0;
// These values the counters for each
accumulator.
int main()
{
while(1){
// This
will run until x or X is entered as an input.
cout<<" Enter the type of
computer or enter x/X to compute the scores : ";
char choice;
cin>>choice;
int score;
switch(choice)
// in each case
we increment the values of the accumulator
{
// and the counter. except the x case in that ,
we print
case
'm':
// the averages of the score or
print no user if no entry of
case
'M':
// that type is made.
cout<<" Enter the score : ";
cin>>score;
sumM += score;
countM++;
break;
case
'w':
case
'W':
cout<<" Enter the score : ";
cin>>score;
sumW += score;
countW++;
break;
case 'o':
case 'O':
cout<<" Enter the score : ";
cin>>score;
sumO += score;
countO++;
break;
case 'x':
case 'X':
if(sumM==0){
cout<<"No Mac
Users.\n";
}
else{
printf("The average test
score for mac users is : %.1f\n", sumM/countM);
}
if(sumW==0){
cout<<"No Windows
Users.\n";
}
else{
printf("The average test
score for windows users is : %.1f\n", sumW/countW);
}
if(sumO==0){
cout<<"No Other
Users.\n";
}
else{
printf("The average test
score for other users is : %.1f\n", sumO/countO);
}
exit(0);
break;
default:
break;
}
}
return 0;
}