i need help

i think i get the basics it just isn't displaying. can someone help me please. my code runs once then repeats the score every time. I want it to ask me midterm and final every time and then apply the proper grade. it give me score from first time and doesnt show graade at al.
I am a beginner so if you could help i would really appreciate it. here is my code

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int midterm;
int final;


cout << "please enter midterm grade: ";
cin >> midterm;
while (midterm < 0 || midterm > 200)
{
cout << "Please enter valid amount must be 0 or greater or 200 or less. please enter grade: ";
cin >> midterm;
}
cout << " please enter final grade: ";
cin >> final;
while (final < 0 || final > 200)
{
cout << "Please enter valid amount must be 0 or greater or 200 or less. Please enter grade";
cin >> final;
}

int total;
total = final + midterm;

if (total > 360 || total <=400)
{
cout << "your letter grade is A";
}
else if (total > 320 || total< 359)
{
cout << "your letter grade is B";
}
else if (total > 280 ||total < 319)
{
cout << "your letter grade is C";
}
else if (total > 279 ||total < 241)
{
cout << "your letter grade is D";
}
else if (total < 240)
{
cout << "your letter is F";

}


}
The union of numbers that meet "total > 360 || total <=400" is every real number. You want &&, not ||. You could also simplify the conditions to not require ands or ors. If this is not the issue, please say precisely what your input is, and what is being output that's wrong.
Last edited on
hey ganada i made that change it didnt do anything. my code shows me midterm and final grade added together but it isnt giving me the letter that goes along with it. for intance 340 is a B. when it displays tho it onlysays 340 and no letter. also it doesnt allow me to ask question with new answer everytime. if the first score is 340 then it doesnt change or go away? i want it to ask me for mid term and ifnal score evry time then give me grade?

here is how it comes out

midTerm 150
finalTest200
finalGrade: 350

Next students Grades (-1 to stop):

150
finalGrade: 350

Next students Grades (-1 to stop):









@Colton, show your revised code (below this post), and please use code tags (first item on the format menu).
Without checking that a number has been entered, possibly:

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

int main() {
	int midterm {};
	int final {};

	cout << "Please enter midterm grade: ";

	while ((cin >> midterm) && (midterm < 0 || midterm > 200))
		cout << "Please enter valid amount must be 0 or greater and 200 or less. please enter grade: ";

	cout << "Please enter final grade: ";

	while ((cin >> final) && (final < 0 || final > 200))
		cout << "Please enter valid amount must be 0 or greater and 200 or less. Please enter grade";

	const auto total {final + midterm};

	if (total > 360 && total <= 400)
		cout << "your letter grade is A";
	else if (total > 320 && total < 359)
		cout << "your letter grade is B";
	else if (total > 280 && total < 319)
		cout << "your letter grade is C";
	else if (total > 279 && total < 241)
		cout << "your letter grade is D";
	else
		cout << "your letter is F";
}


Now you add an outer loop to process multiple grades.
Last edited on
Another thing to think about: In addition to changing the ||s to &&s, what happens if the total comes out to, say, exactly 360 or 359? And what error handling, if any, do you want to happen if the number entered is > 400?

colton, show your full, revised code and then I'm sure somebody will try to interpret what you wrote. Your current code doesn't even have a "-1 to stop" outer loop.
Last edited on
@colton,
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either
By using functions which probably comes later on you can combine the midterm and final input while loops as a single operation but this addresses your problems by the look of it.

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
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>

// #include <iomanip> NOT BEING USED

using namespace std;

int main()
{
    int midterm{0};
    int final{0};
    
    while (
           (cout << "please enter midterm grade: " &&
            cin >> midterm &&
            midterm < 0) || midterm > 200
           )
    {
        cout << "Please enter valid amount must be 0 or greater or 200 or less. please enter grade: ";
        // cin >> midterm;
    }
    
    while (
           (cout << "please enter final grade: " &&
            cin >> final &&
            final < 0) || final > 200
           )
    {
        cout << "Please enter valid amount must be 0 or greater or 200 or less. please enter grade: ";
        // cin >> final;
    }
    
    
    int total{0};
    total = final + midterm;
    char letter{'?'};
    
    if (total >= 360) // || total <=400)
    {
        letter = 'A';
    }
    else if (total >= 320) // || total< 359)
    {
        letter = 'B';
    }
    else if (total >= 280) // ||total < 319)
    {
        letter = 'C';
    }
    else if (total >=240) // 279 ||total < 241)
    {
        letter = 'D';
    }
    else // if (total < 240)
    {
        letter = 'F';
    }
    
    cout
    << " Your total grade is " << midterm + final << endl
    << "Your letter grade is " << letter << endl;
}


please enter midterm grade: 123
please enter final grade: 146
 Your total grade is 269
Your letter grade is D
Program ended with exit code: 0
Topic archived. No new replies allowed.