0

Is logic correct??

#include <iostream> using namespace std; int main() { int hovercraft; cin>>hovercraft; int costhc=20000000; int cost=(hovercraft*3000000)-1000000; if(cost>costhc){ cout<<"profit"; } else{ if(cost<costhc){ cout<<"loss"; } else{ cout<<"broke even"; } } return 0; } You run a hovercraft factory. Your factory makes ten hovercrafts in a month. Given the number of customers you got that month, did you make a profit? It costs you 2,000,000 to build a hovercraft, and you are selling them for 3,000,000. You also pay 1,000,000 each month for insurance. Task: Determine whether or not you made a profit based on how many of the ten hovercrafts you were able to sell that month. Input Format: An integer that represents the sales that you made that month. Output Format: A string that says 'Profit', 'Loss', or 'Broke Even'. Sample Input: 5 Sample Output: Loss

20th Jun 2024, 6:54 PM
Haram Abbas Lar
Haram Abbas Lar - avatar
3 Antworten
0
will int support such a big number?
20th Jun 2024, 7:33 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
0
Logic looks solid to me
20th Jun 2024, 11:14 PM
Sean Miles
Sean Miles - avatar
0
Logic is ok but not really clear. But this will fail Code Coach because you didn't capitalize the expected outputs (ex. Profit, not profit)
23rd Jun 2024, 4:05 AM
Scott D
Scott D - avatar