I'm having trouble with a piece of C++ code where it seems like one of my if statements is being ignored. I'm not getting any error messages in the terminal, but the first if statement isn't working as I expected when I run a test. I suspect that the problem might involve the last if statement and some else if statements, but I'm not sure how to troubleshoot or fix it since I'm still new to C++. Here's the code I'm working with:
double score;
char LetterGrade;
cout <> score;
cout <> LetterGrade;
if ( ! ( score > 0 && score < 100) )
{
cout << "Invalid Score";
return 0;
}
if (! (LetterGrade =='A' || LetterGrade == 'B' || LetterGrade == 'C' || LetterGrade == 'D' || LetterGrade == 'F' ) )
{
cout << "Invalid letter grade";
return 0;
}
if ( score < 60)
cout <= 60 && score <=69)
cout <=70 && score <= 79)
cout <=80 && score <= 89)
cout <=90 && score <= 100)
cout << "Excellent Job! A";
4 Answers
You should consider always flushing the output when switching between cout and cin. For instance, instead of:
cout <> score;
Try this:
cout << "Enter your homework score: " <> score;
That might fix the issue.
Another way to debug is by adding some print statements before your if conditions to check the values being entered. For example, print out the score right before you check it. It'll help you see what's actually happening.
You might need to flush your cout buffer. If you don't use std::endl or std::flush, the output might get delayed. Try adding std::flush at the end of your cout statements to force it to print immediately.
Don't forget to check what the score variable contains before using it in the if statements. A simple print right before the ifs can help you ensure that it's holding the expected value.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically