+ 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; }
7 Antworten
+ 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?
+ 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){
+ 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.
+ 1
OH. That makes a lot more sense. Thank You!
+ 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.
+ 1
Being a good coder doesn't mean you won't make mistakes, it means you will make mistakes and still keep learning code.
0
+×÷-