Do-While Loop problem

For your birthday, you received $10 gift certificate for an online music store. You can buy songs until your money is gone. Write a C++ program that allows a user to repeatedly buy songs from your online music store. The initial balance is $10. For simplicity, we will just input from the user the cost of the song (usually $0.99, $1.99 or $2.99) and ignore the song name and artist name. Exit the loop when the user doesn't have enough money to buy more songs and display the remaining balance. A sample output looks like the following:
Enter the cost of the song, ($0.99, $1.99, or $2.99): 0.99
Your remining balance is: 9.01.
Enter the cost of the song, ($0.99, $1.99, or $2.99): 1.99
Your remining balance is: 7.02.
Enter the cost of the song, ($0.99, $1.99, or $2.99): 0.99
Your remining balance is: 6.03.
Enter the cost of the song, ($0.99, $1.99, or $2.99): 2.99
Your remining balance is: 3.04.
Enter the cost of the song, ($0.99, $1.99, or $2.99): 2.99
Your remining balance is: 0.05.
Sorry, balance is $0.05. You can't buy more songs.


This is what I have so far. I don't understand how to do this fully.

#include <iostream>

using namespace std;

int main()
{

int cost;
int sum;
int count;

sum = 10;
count = 0;
cost = 1;

do
{
cout << "Enter the cost of the song, ($0.99, $1.99, or $2.99): " ;
cin >> cost;
sum = sum - cost;
cout << "Your remaining balance is: " ;
cout << sum << endl;
count++;
}
while (count > 0.99);

return 0;

}
You are very close, but you have three problems.

1) You are looping while count > 0.99, but you want to loop until your balance (which
you are keeping in the "sum" variable) is less than 0.99.

2) You are asking the user to enter a floating point number, you are reading it into
an integer.

3) You are not validating the user's input (not sure if your assignment calls for that;
usually validation of input is a given).

Thank you!
Topic archived. No new replies allowed.