+ 2

Hovercraft c++ approach

Test case 3,4 showing failure ,can anybody tell why !! int n ; cin >>n; if (n<7) { cout<<"Loss"; } if (n==7) { cout<<"Broke Even"; } else{ cout<<"Profit"; } And what's your approach for that

18th Sep 2020, 12:14 PM
Mantu kumar
Mantu kumar - avatar
4 Antworten
+ 2
Try to put 5 Output: LossProfit How to fix? 1. You can use switch and case statements 2. You can use ternary operator 3. You can put 'else if (n == 7)' instead of 'if (n == 7)'
18th Sep 2020, 12:19 PM
Namit Jain
Namit Jain - avatar
+ 4
if( profit > 0){ return "Profit"; } if( profit < 0 ){ return "Loss"; } return "Broke Even"; }
18th Sep 2020, 12:27 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
🗡️Jasprit I will apply your method , and let you know
18th Sep 2020, 12:32 PM
Mantu kumar
Mantu kumar - avatar
+ 1
Try else if (n == 7)
18th Sep 2020, 12:18 PM
Derlas Forenly
Derlas Forenly - avatar