I’m making a Grade log application and I have this piece of code here which doesn’t work as I intend it to work. (It compiles great with no errors but doesn’t work) (please keep in my mind I am a begginer in C++, thank you for your time and knowledge to help me learn also).
(The testscore is being given from a series of questions where the value gets a +1 if its correct and a -1 if its wrong.
I think the error is in the => it gets conflicted one with the other but i dont know how to give a value for ex. if the score is < 20 cout = failed if its <40 failedgood but see 20 is < 40 so one overrides the other how could i put if its from 20-40 cout = failed good and if its from 0 – 20 cout = failed. I hope you understand what I mean.
int testscore;
string studentmark;
if ( testscore == 10 )
{
studentmark == ( "failed" );
}
else if ( testscore >= 11 && testscore <= 20 )
{
studentmark == ( "closebutfailed" );
}
else if ( testscore >= 21 && testscore <= 30)
{
studentmark == ( "passed" );
}
else if ( testscore >= 31 && testscore <= 40 )
{
studentmark == ("excelent");
}
else if ( testscore >=49 )
{
studentmark == ("hasteachersbook");
}
cout << "Studentmark is:" << studentmark << endl;
First off, your problem is that you should use a single equals sign for assignment, e.g.
Second, you’re probably better off writing these if statements as
Because that’s easier to read, and the presence of the
elsestatement means you don’t have to test thattestscoreis greater than the amounts you’ve already covered.