Student Portfolio >> Index >> Coding >> Exercise 18
//Reads in 10 student results and displays averages of a's b's c's etc and fails #include<iostream.h> int main() { int score, i, A=0, B=0, C=0, fails=0, numa=0, numb=0, numc=0, numfail=0, avea=0, aveb=0, avec=0, avefail=0; for(i=1; i<=10; i=i++) {cout << "Enter Score Number " << i << ": "; cin >> score; if (score >=75) { numa++; A=A+ score; avea = A/numa; } else if (score >=65) { numb++; B=B+score; aveb = B/numb; } else if (score >=50) { numc++; C=C+score; avec = C/numc; } else { numfail++; fails = fails + score; avefail = fails/numfail; } } cout << "Their was " << numa << " A's and the average scores for this grade is " << avea << "\n"; cout << "Their was " << numb << " B's and the average scores for this grade is " << aveb << "\n"; cout << "Their was " << numc << " C's and the average scores for this grade is "<< avec << "\n"; cout << "Their was " << numfail << " fails at an average of " << avefail << "\n"; return 0; } << Back Forward >> |
Copyright 2005 Kerstin Kegel