Question: Please debug the C + + code showed below,thanks! #include using namespace std; int main ( ) { cout < < Welcome to your first
Please debug the Ccode showed below,thanks!
#include
using namespace std;
int main
cout "Welcome to your first C lab!" endl;
cout In this program, let's pretend you want to buy C learning materials." endl;
cout "After fixing the codes below, compare this program output with the sample output to verify your work." endl;
cout endl;
int balance;
cout "Please enter the amount of money you have: ;
cin balance;
TODO : Fix the line below. It currently will print "You haveHKD if your input was
For details, check the expected output below
cout "You have" balance HKD endl;
cout endl;
cout "You decide to buy the textbook for HKD endl;
TODO : Fix the line below. It currently does not subtract balance by correctly.
balance ;
cout "Remaining balance: balance HKD endl;
cout endl;
TODO : Fix the three lines below. They are not in the correct order,
which causes the output does not reflect the real current remaining balance correctly
cout "You decide to buy a notebook for HKD endl;
cout "Remaining balance: balance HKD endl;
balance balance ;
cout endl;
cout "Because you need money, you would like to sell your pencil." endl;
int price;
cout "Please enter the price for your pencil: ;
cin price;
TODO : Fix the if statement below.
The shop allows you to sell a pencil, but the price cannot be higher than
Hint: Do you use the correct variable in the following if statement?
if balance
cout "The price balance is too high, you could not sell your pencil." endl;
else
balance balance price;
cout "Remaining balance: balance HKD endl;
cout endl;
cout "Lastly, you try to buy a new laptop for HKD endl;
TODO : Fix the if statement below.
Currently if the user does not have enough money, it is still subtracted.
Hint: C is strict with curly braces.
if balance
cout "You don't have enough money left." endl;
else
cout "You have enough money left, you can purchase the laptop." endl;
balance balance ;
cout "Remaining balance: balance HKD endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
