Program will display the same letter over and over

So i'm trying to write a program that will prompt the user to keep entering as much student grades as needed. My goal would be to first ask for one grade and have the letter grade displayed on the screen when that is done I would like it to ask for another grade repeating the process over and over in till i press a button that says to stop. can you point me into the right direction?

My code thus far...

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
#include <iostream>
using namespace std;

int main()
{
	int number;
	cout << "enter a number ";
	cin >> number;
	
	while (!==-1)
	{

		if (number >= 90)
		{
			cout << "A\n";
		}
		else if ((number < 90) && (number >= 80))
		{
			cout << "B\n";
		}
		else if ((number < 80) && (number >= 70))
		{
			cout << "C\n";
		}
		else if ((number < 70) && (number >= 60))
		{
			cout << "D\n";
		}
		else
		{
			cout << "F\n";
		}
	}
}
Last edited on
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/

 
while ( !== -1) 


 In function 'int main()':
10:13: error: expected primary-expression before '!=' token
10:15: error: expected primary-expression before '=' token
1. Use code tags please when posting code.

2. Your while loop condition (while(!==-1)) makes no sense. Might try: while (number != -1){...}

3. Your endless loop is because your input (cin >> number) is outside the loop so if number isn't entered as -1 the loop continues without being able to enter another value to number. Place (cin >> number) inside your loop. HTH
closed account (LA48b7Xj)
You can write your loop like this...

1
2
3
4
while(cin >> number)
{
    /* ... */
}


And any input that is not a number will exit the loop.
Last edited on
Topic archived. No new replies allowed.