how do i format the output correctly? project already overdue but thought i'd ask

I am using IF ELSE statement and i already included what's needed for setw, as I formatted everything else, but i cannot for the life of me get my IF ELSE statements to format properly and it's driving me nuts.

what i don't understand is how I was able to use setw, fixed, showpoint, etc without trouble but now all of sudden i can't format my last statements.

i need a response asap if possible please
Response to what?

I see no code to comment on.

1
2
3
4
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string> 


1
2
3
4
5
6
7
8
9
10
	if (grade >= 90 && grade < 100)
		cout << setw(20) << "A" << endl;
	else if (grade >= 80.99 && grade < 89.99)
		cout << setw(20) << "B" << endl;
	else if (grade >= 70.99 && grade < 79.99)
		cout << setw(20) << "C" << endl;
	else if (grade >= 60.99 && grade < 69.99)
		cout << setw(20) << "D" << endl;
	else if (grade >= 0 && grade < 60)
		cout << setw(20) << "F" << endl;
Your setw() is working just fine. However, you have some problems with your if statements.
Several grades do not get a letter grade at all. Why are you using .99 on your tests?
e.g. 100,80,70,60 all result in no grade because of the way you're testing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Grade? 100
Grade? 0
                   F
Grade? 90
                   A
Grade? 80
Grade? 70
Grade? 60
Grade? 61
                   D
Grade? 50
                   F
Grade? -1
Press any key to continue . . .

Last edited on
Topic archived. No new replies allowed.