My code is supposed to give back the correct amount of change in cents(example is give me 25 cents and it prints out 1 twenty cent coin 5 cent) but it keeps coming up with random numbers, need help!!!!
Code:
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <ctype.h>
char Displaybanner(Help)
{
int fifty, twenty, ten, five, result;
char option;
printf("\Hello Bank teller.");
do
{
printf("\n\nDo you need help (Y/N)");
option = getch();
option = toupper (option);
}
while (!((option=='Y') || (option=='N')));
printf("%c\n",option);
if (option=='Y')
printf("\nEnter the amount of cents that needs to be returned to the customer: ");
scanf("%d%*c", &result);
return result;
}
int Calculate()
{
int fifty, twenty, ten, five, result;
if ((result<0) || (result>95) || (result%5>0))
fifty = result / 50;
result %= 50;
twenty = result / 20;
result %= 20;
ten = result / 10;
result %= 10;
five = result / 5;
result %= 5;
printf("To make change for the amount you entered, you will need the following coins:\n\n", result);
if (fifty > 1)
printf("%d Fifty cent piece's.\n", fifty);
if (fifty == 1)
printf("%d Fifty cent piece.\n", fifty);
if (twenty > 1)
printf("%d Twenty cent piece's.\n", twenty);
if (twenty == 1)
printf("%d Twenty cent piece.\n", twenty);
if (ten > 1)
printf("%d Ten cent piece's\n", ten);
if (ten == 1)
printf("%d Ten cent piece.\n", ten);
if (five > 1)
printf("%d Five cent piece's\n", five);
if (five == 1)
printf("%d Five cent piece.\n", five);
return result;
}
int main ()
{
int fifty, twenty, ten, five, result;
result = Displaybanner();
Calculate();
}