+ 1

Can anyone solve this problem why && operator not working well ya something is wrong

https://code.sololearn.com/cVqcajonKCRX/#c Im just specify the if else statement if total == 100 and marks is greater than 0 then enter but if you enter the value of total 100 and value of marks is 0 it show the ans invalid

6th Aug 2020, 6:23 AM
RDS
4 Answers
+ 2
The && operator is working just fine. The problem that I see is the return value from Percentage() is ambiguous. When it returns 0.0, the caller cannot determine whether it was FALSE or an actual zero percentage result from 0.0/100.0. In main(), the FALSE result is checked first, so that is what it reports - invalid. There would be similar problem for TRUE versus 100.0/100.0. I recommend defining an enum of three valid return statuses from Percentage(). So instead of FALSE, TRUE, and *pct, return only the enum values (like VALID = 0, INVALID1 = 1, INVALID2 = 2) from Percentage(). [Of course, also change the function return data type to be the enum instead of float]. Then in main() compare the return value against the possible enum values to determine whether to use the result returned in Ans.
6th Aug 2020, 9:39 AM
Brian
Brian - avatar
+ 1
Brian I'll try Ty's 👍
6th Aug 2020, 11:00 AM
RDS
0
I think, your code condtion are if(iTotal == 0) you check only 0 , so you enter any number for total except 0 that can return only FALSE (print: invalid output)
6th Aug 2020, 7:26 AM
Valentina
Valentina - avatar
0
Ji Ji But what if imarks and total is also zero then it going to show invalid input
6th Aug 2020, 10:57 AM
RDS