Colour Theme Font Size Options
 
 
 
Exercise 4

Event Loops: Online Music Store Exercise

For your birthday, you received a $10 gift certificate for an online music store. The cheapest song in the store costs $0.99. You can buy songs until you can't afford any more songs.

Instructions:

  • Write a C++ program called ex4_musicStore.cpp that allows a user to repeatedly buy songs from an online music store.
  • Set an initial balance of $10.
  • Use a loop to keep asking the user to buy songs while there's at least enough balance to afford the cheapest song.
    • For simplicity, just get the cost of a song from the user and ignore the song and artist name.
    • Check to see if the user can afford the song before completing the purchase. Make sure that negative balances will not happen.
    • Give feedback to the user indicating whether their purchase was successful and how much money they have left.
  • When the loop ends, display a goodbye message with the remaining balance.
Here's the output from a sample run:
      
Enter the cost of a song: 0.99 Song purchased for $0.99! Enjoy!!! Your remaining balance is: 9.01 Enter the cost of a song: 1.99 Song purchased for $1.99! Enjoy!!! Your remaining balance is: 7.02 Enter the cost of a song: 2.99 Song purchased for $2.99! Enjoy!!! Your remaining balance is: 4.03 Enter the cost of a song: 1.99 Song purchased for $1.99! Enjoy!!! Your remaining balance is: 2.04 Enter the cost of a song: 2.99 Your choice is too expensive!!! Choose another one please! Your remaining balance is: 2.04 Enter the cost of a song: 0.99 Song purchased for $0.99! Enjoy!!! Your remaining balance is: 1.05 Enter the cost of a song: 1.99 Your choice is too expensive!!! Choose another one please! Your remaining balance is: 1.05 Enter the cost of a song: 0.99 Song purchased for $0.99! Enjoy!!! Your remaining balance is: 0.06 Your balance is $0.06. You cannot buy more songs. Come again!

When you are done:

  • Take a screenshot of your IDE and console window after compiling and running the program. Use input similar to the above sample run.
  • For this exercise, you will have: ex4_musicStore.cpp.
  • If you have completed everything, congratulations! Please upload .cpp files and screenshots to URCourses.