0

Howdy! So I'm taking this online intro to C class and have not been able to get in touch with my instructor because I think he's on vacation.Grrrrr. Anyway, If someone could give me some hints on what is wrong with this code I would really appreciate it. I am NOT looking for answers,just hints. Thanks in advance!

# include <iostream>
using namespace std;
//
int main ()
{
    //declare array
    int scores[20] = {90, 54, 23, 75, 67, 89, 99, 100, 34, 99, 97, 76, 73, 72, 56, 73, 72, 20, 86, 99};
    //Declare variables
    int searchScore = 0;//Statement 1
    int total = 0;
    //
    cout << "Studentscore11 Program Output. \n\n";
    //
    cout << "Enter a score from 0 through 100 (-1 to end): ";
    cin >> searchScore;//Statement 2
    //
    while (searchScore >= 0);//Statement 3
    {
          total = 0;
          //search for score
          for (int x = 0; x < 20; x += 1)//Statement 4
          {
              if (scores[20] == searchScore);//Statement 5
              {
                 total = total + 1;
                 }//End if
              }//End for
           //Display total
           cout << "Number of students earning a score of " << searchScore << ": " << total << endl << endl;
           cout << "Enter a score from 0 through 100 ( -1 to end): ";
           cin >> searchScore;//Statement 6
           }//End while 
cout << "\n\n";
system("pause");
return 0;
}//End of main function
3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by WaltP
0

Well, one thing that's an issue is the scores[20] on line 23.
This is zero-based, so scores[20] is the 21st element in a 20 element array.
(Outside the bounds of the array)

Edited by thines01: clarity

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.