Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Desperate plee for Help. C program for ATM. (http://www.go4expert.com/forums/desperate-plee-help-c-program-atm-t17493/)

TigerTank77 13May2009 07:23

Desperate plee for Help. C program for ATM.
 
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.

xpi0t0s 13May2009 16:30

Re: Desperate plee for Help. C program for ATM.
 
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)


All times are GMT +5.5. The time now is 16:43.