1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
Roy Hammond
Source code
Chapter 11, exercise 27
//Advanced27.cpp - displays the number of students
//earning a specific score
//Created/revised by Roy Hammond on 11-19-12
#include <iostream>
using namespace std;
int main()
{
//declare array and variables
int arrayScores[200] = {10, 50, 54, 50, 10, 75, 67, 89, 99, 100, 34, 99, 50, 34, 72, 88, 5,
97, 76, 73, 72, 56, 73, 50, 5, 10, 50, 20, 86, 99, 50, 20, 5, 42, 68, 77, 34, 22,
23, 55, 20, 10, 5, 66, 88, 5, 88, 66, 43, 50, 47, 50, 55, 54, 22, 20, 5, 33, 55,
33, 44, 55, 66, 23, 5, 20, 50, 20, 55, 100, 99, 100, 23, 50, 66, 23, 55, 20, 5,
20, 10, 100, 5, 88, 100, 99, 20, 34, 55, 5, 10, 20, 10, 50, 23, 77, 10, 5, 55, 50,
5, 34, 55, 60, 100, 70, 75, 50, 23, 55, 20, 60, 100, 2, 5, 45, 49, 50, 100, 50, 74,
59, 70, 100, 10, 60, 23, 5, 100, 10, 5, 100, 77, 55, 43, 20, 50, 100, 66, 100, 77,
100, 5, 90, 10, 50, 10, 100, 55, 60, 45, 50, 11, 10, 55, 5, 11, 100, 50, 98, 85,
5, 20, 10, 10, 50, 100, 20, 50, 53, 20, 100, 59, 20, 80, 90, 45, 100, 10, 59, 88, 90,
100, 50, 20, 100, 10, 55, 10, 100, 20, 54, 55, 100, 60, 10, 5, 10, 5, 88};
int searchFor = 0;
int numberScored = 0;
//get score to search for
cout << "Please enter a test score or enter -1 to end the program:";
cin >> searchFor;
system ("cls");
while (searchFor > -1)
{
for (int sub = 0; sub < 200; sub += 1)
if (arrayScores[sub] == searchFor)
numberScored += 1;
//end if
//display the results
cout << numberScored << " students scored " << searchFor << "." << endl;
//get a new score
cout << "please enter another score to search for:" ;
cin >> searchFor;
numberScored = 0;
system ("cls");
} //end while
system("pause");
return 0;
} //end of main function
|