+ 1

I need help with Hovercraft Code Coach

I can’t figure out why the program is outputting “Profit” no matter what. #include <iostream> using namespace std; int main() { int cost=-2000000; int sell=3000000; int insurance=-1000000; int hovercraft=0; cin>>hovercraft; int intake=(cost+sell)*hovercraft; int profit=intake+insurance; if (profit>0){ cout<<"Profit"<<endl; } if (profit=0){ cout<<"Broke Even"<<endl; } if (profit<0){ cout<<"Loss"<<endl; } return 0; }

5th Jan 2020, 3:13 AM
Whanos
Whanos - avatar
7 Respostas
+ 8
You are missing one part of the prompt. Reread the prompt. Here’s a hint: How many hover crafts do you MAKE per month? How many hovercrafts do you SELL per month?
5th Jan 2020, 3:26 AM
Ivan
Ivan - avatar
+ 3
I feel really dumb now. After reworking some of the math and being really confused because it wasn’t still working, all I had to do was change a = to == in if (profit=0){
5th Jan 2020, 6:05 AM
Whanos
Whanos - avatar
+ 2
You are counting your expenses assuming you make a hoverboard only when you sell one, but you already made all your hoverboards. In your code, you will ALWAYS profit because you never made more hoverboards than you needed. But in reality, you should have spent exactly the same every month, because you already know how many you made.
5th Jan 2020, 4:07 AM
{ Aza }
{ Aza } - avatar
+ 1
OH. That makes a lot more sense. Thank You!
5th Jan 2020, 5:21 AM
Whanos
Whanos - avatar
+ 1
Whanos dude dont feel stupid. thats like 90% of our job. i once spent three hours trying to resolve a bug. I read stackoverflow posts and ruby articles, only to realize i accidently pressed the space bar twice on a string declration.
5th Jan 2020, 6:55 AM
Ivan
Ivan - avatar
+ 1
Being a good coder doesn't mean you won't make mistakes, it means you will make mistakes and still keep learning code.
5th Jan 2020, 7:36 AM
{ Aza }
{ Aza } - avatar
0
+×÷-
6th Jan 2020, 11:27 PM
David Toba
David Toba - avatar