The Vending machine dilemma! <3 Thanks ahead of time for the help.

This is a discussion on The Vending machine dilemma! <3 Thanks ahead of time for the help. within the C Programming forums, part of the General Programming Boards category; Here is part of my code: Code: char selection; double item_cost; double amount; double owed; double total; printf("\nPlease deposit your ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    16

    The Vending machine dilemma! <3 Thanks ahead of time for the help.

    Here is part of my code:

    Code:
    char selection;
    double item_cost;
    double amount;
    double owed;
    double total; 
    
    
    printf("\nPlease deposit your money by selection:\n1: %.2f\n2: %.2f\n3: %.2f\n4: %.2f\n5: %.2f\n",5.00,1.00,0.25,0.10,0.05);
    
    printf("Deposit amount:%d");
    scanf("%lg", &amount); 
    
    printf("Price of Item %c is %lg", &selection, &item_cost);
    	
    printf("Balanced entered:%lg", &amount);
    Here is the output I am trying to replicate:
    Code:
    Please deposit your money by selection:
         1-$5.00
         2-$1.00
         3-$0.25
         4-$0.10
         5-$0.05
    
    Deposit Amount: 1
    
    ------------------------------
    Price of Item: k is $1.00
    
    Balance Entered: $5.00
    --------------------------------------------------------------------------
    I'm confused on how i get the 1/2/3/4/5 to equal the right price since the deposited amount is being represented by the selection and not the price.

  2. #2
    Registered User
    Join Date
    Jan 2010
    Posts
    69
    try using a switch statement
    Code:
    int choice;
    
    printf("please deposite your money by selection:");
    printf("1");
    and so on...
    
    scanf("%d", &choice);
    
    switch(choice)
    {
    case 1:
    break;
    
    case 2:
    break;
    }
    then you can write separate functions for each case....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 07:56 AM
  2. inputting time in separate compilation
    By sameintheend01 in forum C++ Programming
    Replies: 6
    Last Post: 03-13-2003, 03:33 AM
  3. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM
  4. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 145
    Last Post: 04-09-2002, 06:17 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21