Value wont show

The program wont let me print the value of a b c and d =(, im sure it has something to do with my syntx

printf("\n50 cents,%a\n"); //What kind of code should i use if u want to show the value of a? same goes to b c and d.




int Result(int cash)
{
int a;
int b;
int c;
int d;

a = 0;
b = 0;
c = 0;
d = 0;

do{
a = a + 1;
} while(cash >= 50);
cash = cash - 50;
printf("\n50 cents,%a\n");

do{
b = b + 1;
} while(cash >= 20);
cash = cash - 20;
printf("\n20 ,%b\n");

do{
c = c + 1;
} while(cash >= 10);
cash = cash - 10;

printf("\n10 cent change,%c\n");

do{
d = d + 1;
} while(cash >= 5);
cash = cash - 5;
printf("\n5 cent change,%d\n");

return;
Look up the syntax of printf(). That's not how you print a variable; the % should be followed with the type specifier, then the variables should be listed as separate arguments after the string.
I change it but it still wont print. Whats the command for displaying the value of a?
I guess is not % after all I tried & and it dosent work either.
Sry I'm complete newbie in programing.


int Result(int cash)
{
int a;
int b;
int c;
int d;

a = 0;
b = 0;
c = 0;
d = 0;

do{
a = a + 1;
} while(cash >= 50);
cash = cash - 50;
printf("\n50 cents\n");
printf("%a");

do{
b = b + 1;
} while(cash >= 20);
cash = cash - 20;
printf("\n20 cents\n");
printf("%b");

do{
c = c + 1;
} while(cash >= 10);
cash = cash - 10;

printf("\n10 cent change\n");
printf("%c");

do{
d = d + 1;
} while(cash >= 5);
cash = cash - 5;
printf("\n5 cent change,%d\n");
printf("%d");

return;
}
Here is the function page for printf():
http://cplusplus.com/reference/clibrary/cstdio/printf/

With that, you should be able to figure out the proper syntax. If you have problems with it, post again, but I hope the example will show you how it works.
Ty very much
Ok i fix it but the problem is the program didnt loop and it only do the calculation once when I want it every time cash cash is bigger than > coin = add value of a.

int Result(int cash)
{
int a;
int b;
int c;
int d;

a = 0;
b = 0;
c = 0;
d = 0;

do{
a = a + 1;
} while(cash >= 50);
cash = cash - 50;
printf("\n50 cents\n");
printf("%d", a);

do{
b = b + 1;
} while(cash >= 20);
cash = cash - 20;
printf("\n20 cents\n");
printf("%d", b);

do{
c = c + 1;
} while(cash >= 10);
cash = cash - 10;
printf("\n10 cent change\n");
printf("%d", c);

do{
d = d + 1;
} while(cash >= 5);
cash = cash - 5;
printf("\n5 cent change,\n");
printf("%d", d);

return;
}
Any other formula to do this?
when you count the coins, you might want to decrease the cash
for example:
1
2
3
4
5
6
do
{
a = a + 1;
cash = cash - 50;
}
while (cash >= 50);

as about the loop, you have the function
int Result(int cash)
you may call it in a loop somewhere in your program if you want to!
Topic archived. No new replies allowed.