practice program C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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".

11th Feb 2018, 7:51 PM
Jason Ching
Jason Ching - avatar
6 Answers
+ 3
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 <>.
12th Feb 2018, 12:25 AM
Jacob Pembleton
Jacob Pembleton - avatar
+ 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; }
11th Feb 2018, 8:00 PM
Jason Ching
Jason Ching - avatar
+ 1
You should put the cin >> grade; before the switch statement.
12th Feb 2018, 10:10 AM
Jared Bird
Jared Bird - avatar
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.
11th Feb 2018, 7:56 PM
Alex
Alex - avatar
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.
14th Feb 2018, 1:22 PM
Jason Ching
Jason Ching - avatar
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.
14th Feb 2018, 1:29 PM
Alex
Alex - avatar