Program entirely messing up.. Need explanations.

I am an absolute beginner and I need help with this code... I'm practicing this exercise..

1
2
3
4
5
6
7
Write a program that allows the user to enter the grade scored in a programming class (0-100).
If the user scored a 100 then notify the user that they got a perfect score.

★ Modify the program so that if the user scored a 90-100 it informs the user that they scored an A

★★ Modify the program so that it will notify the user of their letter grade
0-59 F 60-69 D 70-79 C 80-89 B 90-100 A


I have multiple questions about this so I will start here

1. It seems no matter what I input I still get the message "You got an A", which makes no sense to me because I stated that if the input is equal to a certain number, for instance if it's equal to 70 it should display that the use got a C.

2. I know how to make numbers count up with something like i++, but I don't understand how I would make it count up for example from 70-79.. I know I could say if the user input is less that 79 then say they got a C, but that wouldn't be correct because if they got a 60 they obviously didn't get a C. I don't know how to make it say less than 79 but more than 69... So I'm trying to find a solution instead of manually typing it out like this

"else if (userGradeInput == 70, 71, 72, 73, 74, 75, 76, 77, 78, 79)
{
cout << "You got a C. " << endl;"


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
 // gradingProgram.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;


int main()
{
	int i = 1;
	int userGradeInput;

	cout << "What grade did you score in programming class? " << flush;
	cin >> userGradeInput;

	if (userGradeInput == 100)
	{
		cout << "You got a perfect score!" << endl;
	}
	else if (userGradeInput == 90, 91, 92, 93, 94, 95, 96, 97, 98, 99)
	{
		cout << "You got an A! " << endl;
	}
	else if (userGradeInput == 80, 81, 82, 83, 84, 85, 86, 87, 88, 89)
	{
		cout << "You got a B. " << endl;
	}
	else if (userGradeInput == 70, 71, 72, 73, 74, 75, 76, 77, 78, 79)
	{
		cout << "You got a C. " << endl;
	}
	else if (userGradeInput == 60, 61, 62, 63, 64, 65, 66, 67, 68, 69)
	{
		cout << "You got a D.." << endl;
	}
	else
	{
		cout << "Error: Please re-enter your grade.." << flush;
	}



	system("pause");
    return 0;
}


the reason I have int i = 1 in this is because I was trying to find out myself through trial and error how to not have to manually type out the numbers but I just can't wrap my head around it.. Thank you guys so much!!
Last edited on
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
// gradingProgram.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>

using namespace std;


int main()
{
	int userGradeInput;

	cout << "What grade did you score in programming class? " << flush;
	cin >> userGradeInput;

	if (userGradeInput == 100)
	{
		cout << "You got a perfect score!" << endl;
	}
	else if (userGradeInput >= 90 && userGradeInput <=99)
	{
		cout << "You got an A! " << endl;
	}
	else if (userGradeInput >= 80 && userGradeInput <= 89)
	{
		cout << "You got a B. " << endl;
	}
	else if (userGradeInput >= 70 && userGradeInput <= 79)
	{
		cout << "You got a C. " << endl;
	}
	else if (userGradeInput >= 60 && userGradeInput <= 69)
	{
		cout << "You got a D.." << endl;
	}
	else
	{
		cout << "Error: Please re-enter your grade.." << flush;
	}

	//system("pause");
    return 0;
}

Topic archived. No new replies allowed.