Help me!!!Important

Discussion in 'C' started by TechPersie, Mar 10, 2013.

  1. TechPersie

    TechPersie New Member

    Joined:
    Mar 10, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    -i need to write a program for an automatic teller machine that dispenses money.
    -The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills.
    -The bills dispensed are 100s, 50s, 20s,and 10s.
    -Write a function that determines how many of each kind of bill to dispense.
    -Also write a function that generates random numbers display this number for user to key in for authentication purposes.

    Please show me the example or the exact solution, thanks!
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    -i need to write a program for an automatic teller machine that dispenses money.
    have you?

    -The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills.

    if number % 10 == 0 then it's a multiple of 10 dollars; otherwise, you'd need to account for singles in some way or they will gum things up.

    -The bills dispensed are 100s, 50s, 20s,and 10s.

    I always thought it was easiest to use an array, but others may have different ways.

    -Write a function that determines how many of each kind of bill to dispense.
    nah

    -Also write a function that generates random numbers display this number for user to key in for authentication purposes.
    you should try this stuff for yourself

    Please show me the example or the exact solution, thanks!
    A couple of ideas; write your own program and post again with your own code if you need help.

    Code:
    int check(int n)
    { 
       return (n / 100 > 0 ? 0 :
               n /  50 > 0 ? 1 :
               n /  20 > 0 ? 2 :
               n /  10 > 0 ? 3 : -1);
    }
    
    ...
    
    int value = 550,
         amounts[4] = { 0 };
    
    while(value > 0)
    {
        switch(check(value))
        {
            case 0 : amounts[0]++;
                     value -= 100;
                     break;
            case 1 : amounts[1]++;
                     value -=  50;
                     break;
            case 2 : amounts[2]++;
                     value -=  20;
                     break;
            case 3 : amounts[3]++;
                     value -=  10;
                     break;
            default : value -= 1;
        }
    }
    
    printf("100s: %d\n 50s: %d\n 20s: %d\n 10s: %d",
            amounts[0], amounts[1], amounts[2], amounts[3]);
    
    ...
    
     
  3. princesse

    princesse New Member

    Joined:
    Mar 19, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    i have the same program to write too.
    How does this work? i'm new Please help.
     
  4. princesse

    princesse New Member

    Joined:
    Mar 19, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    here is what i have done so far..,...
    Code:
    #include <stdio.h> 
    int 
    main (void) 
    { 
    int amount; 
    int number_bills;
    printf("Enter the amount to withdraw :\n"); 
    scanf("%d", &amount); 
    number_bills=0;
    while (amount >= 50) { 
    number_bills++;
    amount -= 50;
    }
    printf("Dispense %d $50 bill(s),\n ",number_bills);
    number_bills=0;
    while (amount >= 20) { 
    number_bills++;
    amount -= 20;
    }
    printf("%d $20 bill(s), \n",number_bills);
    number_bills=0;
    while (amount >= 10) { 
    number_bills++;
    amount -= 10;
    }
    printf("and %d $10 bill(s).\n",number_bills);
    return 0;
    }
     
  5. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    if it's the same program requirements, then you need to check amount for first being a valid number, and then being a multiple of 10. If it's not, reject it and ask again.

    Code:
    loop(...)
    {
        prompt for input
        get input
        validate input
        check input for multiple of 10
    
        if amount is valid, break out of the loop and process the number
    }
    It doesn't look like you've accounted for the 100s.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice