+1

practice program C++

So for practice I decided to look for some practical ways to test the skills I have learned recently. The program I picked instructs to 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 The entire thing should be able to be written using basic input/output logic (if statements, switch statements). my switch statements don't seem to want to be wanting to work. No matter what grade I input it reads " You scored a 90 A" so even if I input 91 or even 95 in the input line I get " You scored a 90 A".

2/11/2018 7:51:58 PM

Jason Ching

6 Answers

New Answer

+2

The problem is in the first line: #include <iostream> Instead of: #include “iostream” Putting the include directory in “” instead of <> indicates that it is relative to the directory of the program. For DLLs, statically linked libraries, or any standard headers, use <>.

+1

I didn't even go any further once I noticed the problem but here it is. #include "iostream" using namespace std; int main() { int grade = 100; switch (grade) { case 90: cin >> grade; cout << "You scored a 90 A\n"; break; case 91: cin >> grade; cout << "You scored a 91 A\n"; break; } return 0; }

+1

You should put the cin >> grade; before the switch statement.

0

To know what you did wrong we need to see your code. We can't guess what happens because you are just giving us a blackbox as information.

0

Thanks for the helps everyone! Jacob was correct. I guess in the excitment of giving myself a project I overlooked that little bit. Also thank you for your input on the cin >> grade statement Jared! That is going to save a lot of lines.

0

Normally you can't use cin inside a switch-case. It's possible, but you would need to build a way around it via function call. The reason it works here is that it gets all inputs at the start.