I am asked to write a simple C program that will accept an integer value in the range of 5-95 and as multiple of 5 representing the number of cents to give to a customer in their change. The program should calculate how many coins of each denomination and display this to the user. Valid coin values are 50,20,10 and 5.
obviously the lass part is wrong and I have no idea what kind of formula to put to count the change in coin, can anyone help me?
#include <stdio.h>
int main(void)
{
int cash;
cash = getCash();
cash = validate(cash);
Result(cash);
int getCash()
{
printf("This programm will caculate your change\n");
printf("Enter the value your change in multiple of 5 from 5-95 : ");
scanf("%d%*c", &cash);
return(cash);
}
int validate(int cash)
{
int max;
int min;
max = 96;
min = 4;
if(min<cash&&cash<max)
cash = cash / 5;
return(cash);
else
printf("You need to enter a number between 0 - 50 and have to be multiple of 5");
return;
}
You should go over your syntax again, you definitely forgot some of the brackets.
Generally, I don't think you need a formula. The most naive solution (if I understood you correctly) is to subtract 50 until the amount of cash is less than 50, then start subtracting 20 ... 10 ... 5 while counting the amount of subtractions. This way you'll get the amount of coins of each denomination needed.
The following error I got is: Type mismatch in redeclaration of "Result1"
Line 55 Declaration terminated incorrectly
Line 67Declaration terminated incorrectly
Line 118Declaration terminated incorrectly
I'm sorry but I'm complete newbie in programing can someone explain to me what i did wrong?
#include <stdio.h>
int main(void)
{
int cash;
cash = getCash();
cash = validate(cash);
Result1(cash);
check1(cash);
Result2(cash);
}
int getCash()
{
int cash;
printf("This programm will caculate your change\n");
printf("Enter the value your change in multiple of 5 from 5-95 : ");
scanf("%d%*c", &cash);
return(cash);
}
int validate(int cash)
{
int max;
int min;
max = 96;
min = 4;
if(min<cash&&cash<max)
cash = cash / 5;
return(cash);
else
printf("You need to enter a number between 0 - 50 and have to be multiple of 5");
return;
}
void Result1(int cash);
{
while(cash => 50)
cash = cash - 50;
return(cash);
else
return(cash);
}
void check1(int cash);
{
if(cash = 45)
{
printf("Your change is 2 Twenty cents and 1 Five cents");
}
else
if(cash = 40)
{
printf("Your change is two 20 cents");
}
else
if(cash = 35)
{
printf("Your change is one 20 cents and one 10 cents and one 5 cents");
}
else
if(cash=30)
{
printf("Your change is one 20 cents and one 10 cents");
}
else
if(cash=25)
{
printf("Your change is one 20 cents and one 5 cents");
}
else
if(cash=20)
{
printf("Your change is one 20 cents");
}
else
if(cash=15)
{
printf("Your change is one 10 cents and one 5 cents");
}
else
if(cash=10)
{
printf("Your change is one 10 cents");
}
else
if(cash=5)
{
printf("Your change is one 5 cents");
}
else
I don't think you got it (actually, the code is getting really messy). Lets go over it... I'll suggest creating a set of variables to handle the types of coins (int coin50 = coin20 = coin10 = coin5 = 0;).
and after receiving a number, say cash and checking it's valid. Then, use a loop to subtract the need amounts (50 can only be subtracted once, so a condition is enough).
I make the code much simpler but I got syntax error can u point up which bracket i miss : D
I'm totaly lost on the syntax
The error i get is line19: Call of nonfunction in function main ( no idea what is it)
line44 Misplace else in function validate (where should i put the else O.o)
linne52 : Declaration terminated incorrectly ( bracket error?)
#include <stdio.h>
int main(void)
{
int cash;
int Result;
cash = getCash();
cash = validate(cash);
Result(cash);
}
int getCash()
{
int cash;
printf("This programm will caculate your change\n");
printf("Enter the value your change in multiple of 5 from 5-95 : ");
scanf("%d%*c", &cash);
return(cash);
}
int validate(int cash)
{
int max;
int min;
max = 96;
min = 4;
if (min<cash&&cash<max)
cash = cash / 5;
return(cash);
else
{
printf("You need to enter a number between 0 - 50 and have to be multiple of 5");
}
return(0);
}
int Result(int cash);
{
a = 0;
x = 0;
c = 0;
d = 0;
while(cash >= 50)
cash = cash - 50;
a = a + 1
printf("&a 50 cents")
while(cash >= 20)
cash = cash - 20;
x = x + 1
print("&x 20 cent change")
while(cash >= 10)
cash = cash - 10;
c = c + 1
print("&c 10 cent change")
while(cash >=5)
cash = cash -5;
d = d + 1
print("&d 5 cent change")
Fix one of the error only 2 left I guess Call of nonfunction in function main
Misplace else in function validate
#include <stdio.h>
int main()
{
int cash;
int Result;
cash = getCash();
cash = validate(cash);
Result(cash);
}
int getCash()
{
int cash;
printf("This programm will caculate your change\n");
printf("Enter the value your change in multiple of 5 from 5-95 : ");
scanf("%d%*c", &cash);
return(cash);
}
int validate(int cash)
{
int max;
int min;
max = 96;
min = 4;
if (min<cash&&cash<max)
cash = cash / 5;
return(cash);
else
{
printf("You need to enter a number between 0 - 50 and have to be multiple of 5");
}
return(0);
}
void Result(int cash)
{
int a;
int x;
int c;
int d;
a = 0;
x = 0;
c = 0;
d = 0;
while(cash >= 50)
cash = cash - 50;
a = a + 1;
printf("&a 50 cents");
while(cash >= 20)
cash = cash - 20;
x = x + 1;
printf("&x 20 cent change");
while(cash >= 10)
cash = cash - 10;
c = c + 1;
printf("&c 10 cent change");
while(cash >=5)
cash = cash -5;
d = d + 1;
printf("&d 5 cent change");