Thread: Purchase Simulator

  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    1

    Purchase Simulator

    The game store will offer both used and new games to sell to customers. In this simulator, you should present the user with the following menu:

    1) Buy New Games
    2) Buy Used Games
    3) Quit

    If the customer would like to buy games (either new or used), you should next ask how many games they would like to buy. The price of each game is pre-determined using the following values:

    Used games sell for $10.00.
    New games sell for $50.00.

    Your program must keep track of the total amount that the customer will spend for their games. This total should be printed out when the user decides to quit.

    If the user quits before buying anything; only print that their final cost will be $0.00.

    If the user inputs an invalid menu choice, your program should tell them that their choice is invalid and present the menu again.

    Output samples
    Welcome to UCF Games!
    What would you like to do?
    1. Buy New Games.
    2. Buy Used Games.
    3. Quit
    1

    How many new games would you like to buy?
    3

    What would you like to do?
    1. Buy New Games.
    2. Buy Used Games.
    3. Quit
    2

    How many used games would you like to buy?
    5

    What would you like to do?
    1. Buy New Games.
    2. Buy Used Games.
    3. Quit
    3

    Your total cost is $200.00.

    If anybody can help me how to start the code please.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Code:
    int main(void)
    {
        // your code here
        return 0;
    }
    I'm only joking a little bit. Seriously, you need to start this yourself. But before you start writing code, you have some preliminary work to do. Programming is much more about problem solving than it is writing code. There is no way you can program a computer to solve a problem if you yourself can't solve it.

    1. Understand the problem. What is being asked of you? What are the requirements? What do you need to complete this?
    2. Solve the problem with "paper and pencil". That is, imagine you had to be the purchase simulator yourself. What would you need to keep track of? Number of new and used games being purchased? Price for new/used games? How would you calculate that by hand?
    3. Write out some pseudo code. This will have the general flow of your final program, but you don't worry about little details. This should be more human-readable than computer-readable.
    4. Turn that pseudo code into real code. Work in small chunks, 5-10 lines at a time. Compile (with warning level set to maximum), fix all errors and warnings, then test to make sure it works correctly. Don't move onto the next 5-10 lines until all previous code is 100% working.

    EDIT: If you get stuck at any of these points, then feel free to ask for more help here. But you need to ask more specific questions, not "can you do some of my homework for me". Perhaps "how do I best store the price of a used game? I was thinking an <your guess here> but am not sure."

    Or maybe "I get this strange compiler error I don't understand, please explain my problem." That would of course be followed by the exact error message, with line number, copied and pasted from your terminal. And of course the code, properly formatted and indented, in [code][/code] tags.

    Or "I'm getting the wrong answer for the following input". Of course, provide your code again, formatted and indented, in [code][/code] tags, and the exact input you provided, the incorrect output you get, and the correct output you should see.
    Last edited by anduril462; 02-03-2014 at 06:14 PM.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Read this -> A development process
    Start small, compile and test often.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simulator
    By MasterAchilles in forum C Programming
    Replies: 10
    Last Post: 11-30-2008, 10:31 PM
  2. Star Simulator
    By G4B3 in forum C Programming
    Replies: 12
    Last Post: 05-11-2008, 03:26 AM
  3. need help with cache simulator!
    By dtogers123 in forum C Programming
    Replies: 3
    Last Post: 04-30-2008, 06:18 PM
  4. blackjack simulator
    By fsufan22 in forum C++ Programming
    Replies: 10
    Last Post: 03-20-2008, 03:16 PM
  5. A Better Format Simulator
    By toonlover in forum C++ Programming
    Replies: 2
    Last Post: 01-07-2006, 06:14 PM