The reason you always get 'F' is because the comparision change is not enough by itself.
You have used lower bounds, this means you need to use >= but you are currently evaluating the possible grades in this order
0 - 299 should result in a F
300 - 349 should result in a D
350 - 399 should result in a C
400 - 449 should result in a B
450 - 500 should result in an A
Since you evaluate F first and everything is >= 0 you always get F
Using minimum bounds with a >= comparison you need to evaluate the grades in this order
450 - 500 should result in an A
400 - 449 should result in a B
350 - 399 should result in a C
300 - 349 should result in a D
0 - 299 should result in a F
That way it will find the first grade that meets the cirteria.
The reason that the program goes into a loop and needs Ctrl-C to exit is that you have the code you use to input the score
//get score to search for
cout << "Enter score (-1 to exit): ";
cin >> searchForScore;
Outside the main while loop instead of inside it.
Ok, I moved the //get score to search for piece of code to the outside of the main while loop and that did make the program stop looping. However, I am still unsure what to do in order to return the appropriate letter grade for whatever score I input. I still receive an F each time. Here is my updated code.
//Ch11AppE11.cpp – displays a grade based on the total number of points
//entered by Ms. Jenkins
//Created/revised by Casey Dockins on 9/23/2006
#include <iostream>
#include <string>
#include <algorithm>
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main()
{
//declare variables and arrays
int searchForScore = 0;
int minPoints[5] = {0, 300, 350, 400, 450};
string grades[5] = {"F", "D", "C", "B", "A"};
while (searchForScore != -1)
{
//get score to search for
cout << "Enter score (-1 to exit): ";
cin >> searchForScore;
//locate position of points in the points array
int y = 0; //keeps track of array subscripts
while (y < 5 && minPoints[y] >= searchForScore)
y = y + 1;
//if score was found, display grade from grades array
if (y > 0 || y < 300)
cout << "grade: " << "F" << endl;
else if
(y > 300 || y < 350)
cout << "grade: " << "D" << endl;
else if
(y > 350 || y < 400)
cout << "grade: " << "C" << endl;
else if
(y > 400 || y < 450)
cout << "grade: " << "B" << endl;
else if
(y > 450 || y <= 500)
cout << "grade: " << "A" << endl;
//end ifs
} //end while
return 0;
} //end of main function
Also, I am using the grades as string data so shouldn't I have to use the getline() somewhere in the code? Thanks for all of the pointers thus far....hopefully with a little more guidance I will finally realize how to make this things work.