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

Recommended Answers

All 2 Replies

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)

The second thing is you need to give us a hint as to what's wrong. We aren't psychic. That's another website.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.