Desperate plee for Help. C program for ATM.

Discussion in 'C' started by TigerTank77, May 13, 2009.

  1. TigerTank77

    TigerTank77 New Member

    Joined:
    May 13, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    So heres the scoop. I need to take this code:

    Code:
    #include "stdio.h"
    #include "conio.h"
    
    int value,rem,bill_50,bill_20,bill_10;
    void dispenser();
    
    int main(void)
    {
    printf("**Welcome**\n\n");
    dispenser();
    getch();
    }
    void dispenser()
    {
    int a,b;
    printf ("Enter the amount you wish to withdrawl\n");
    scanf("%d",&value);
    
      if(((value%10)==0) && (value>0))
    {
        //Calculates 50s                        
        if(value>=50)
        {
        bill_50 = value/50;
        value = value%50;
        printf ("No of 50 Bills is %d \n",bill_50);
        }
        //Calculates 20s
        if((value>=20) && (value<50))
        {
        bill_20 = value/20;
        value = value%20;
        printf ("No of 20 Bills is %d \n",bill_20);
        }
        //Calculates 10s
        if(value==10)
        {
        bill_10 = 1;
        value = value%10;
        printf ("No of 10 Bills is %d \n",bill_10);
        }
        printf("Press 1 for a new transaction and 0 to exit\n");
        scanf("%d",&a);
            
        if(a == 1)
          {
              dispenser();
          }
        if(a == 0)
         {
           printf("Thank you!!");
           exit(0);
         }
      
    
    }
         /*Safety for increments of 10*/
         else
         {
          printf ("Please Enter in Multiples 10 only, thank you \n\n");
          dispenser();
         }
    
    
    
    }
    
    and I have to meet my teacher's demands to have it use pointers, and to pass the variables to the function instead of just using global variables.

    I have NO idea how to do this. I can't program to save my life, I got this code from my roommate lol.

    If anyone can give me an idiot friendly step by step guide, or could just be gracious and fix it, I would be eternally grateful.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    OK, so the first step is to make the variables local to main, so change:
    Code:
    int value,rem,bill_50,bill_20,bill_10;
    void dispenser();
    
    int main(void)
    {
    
    to:
    Code:
    void dispenser();
    
    int main(void)
    {
        int value,rem,bill_50,bill_20,bill_10;
    
    Then dispenser() needs redefining to take pointers to these as parameters. You should have something somewhere in your course notes that shows an example of a function that takes pointer arguments.

    Then within dispenser, change the references to these variables from simple "value" references to pointer references, i.e. "*value" (assuming you keep the same names). For example:
    Code:
    if(*value>=50)
    
     
    shabbir likes this.

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