474,302 views
7 votes
7 votes
Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies.

Ex: If the input is:
0
or less than 0, the output is:
No change
Ex: If the input is:
45
the output is:
1 Quarter
2 Dimes
Fix code please getting error on code
#include
#include
int main()
{
int coin,dollar,quarter,dime,nickel,penny,rem;
scanf("%d\\",&coin);
if(coin<=0)
{
printf("No change\\");
}
else
{
// calculate Dollers
dollar = coin/100;
rem = coin%100;
if(dollar<=1)
{
printf("%d Dollar\\", dollar);
}
else
{
printf("%d Dollars\\", dollar);
}
// calculate Quarters
quarter= rem/25;
rem= rem%25;
if(quarter<=1)
{
printf("%d Quarter\\", quarter);
}
else
{
printf("%d Quarters\\", quarter);
}
// calculate Dimes
dime= rem/10;
rem= rem%10;
if(quarter<=1)
{
printf("%d Dime\\", dime);
}
else
{
printf("%d Dimes\\", dime);
}
// calculate Nickels
nickel= rem/5;
rem= rem%5;
if(nickel<=1)
{
printf("%d Nickel\\", nickel);
}
else
{
printf("%d Nickels\\", nickel);
}
// calculate Pennies
penny= rem;
if(penny<=1)
{
printf("%d Penny\\", penny);
}
else
{
printf("%d Pennies\\", penny);
}
}
return 0;
}
ERROR below
: Compare outputkeyboard_arrow_up
0 / 2
Output differs. See highlights below. Special character legend
Input
45
Your output
0 Dollar 1 Quarter 2 Dime 0 Nickel 0 Penny
Expected output
1 Quarter 2 Dimes
2: Compare outputkeyboard_arrow_up
2 / 2
Input
0
Your output
No change
3: Compare outputkeyboard_arrow_up
0 / 2
Output differs. See highlights below. Special character legend
Input
156
Your output
1 Dollar 2 Quarters 0 Dimes 1 Nickel 1 Penny
Expected output
1 Dollar 2 Quarters 1 Nickel 1 Penny
4: Compare outputkeyboard_arrow_up
0 / 2
Output differs. See highlights below. Special character legend
Input
300
Your output
3 Dollars 0 Quarter 0 Dime 0 Nickel 0 Penny
Expected output
3 Dollars

User Viljami
by
2.7k points

1 Answer

16 votes
16 votes
Hoping it helps. Thanks. Rate please
Write a program with total change amount as an integer input, and output the change-example-1
User Christopher Klein
by
3.1k points