Question

I made this C program to count change and make a slip saying the exact dollar...

I made this C program to count change and make a slip saying the exact dollar and change amount given. every time I run the program it says the change given is 477256577 and i'm not sure what I have done wrong?

#include<stdio.h>
int main(void)
{
char first, last;
int pennies;
int nickels;
int dimes;
int quarters;
int loonies;
int change;
int t_dollars;
int t_cents;
printf("Type in your 2 initials and press return> ");
scanf("%c%c",&first,&last);
printf("%c%c please enter in your coin information.\n",first,last);
printf("Number of pennies>");
scanf("%d",&pennies);
printf("Number of nickels>");
scanf("%d",&dimes);
printf("Number of dimes>");
scanf("%d",&nickels);
printf("Number of quarters>");
scanf("%d",&quarters);
printf("Number of loonies>");
scanf("%d",&loonies);
t_cents=(1*pennies)+(5*nickels)+(10*dimes)+(25*quarters)+(100*loonies);
t_dollars=t_cents/100;
change=t_cents%100;
printf("Dollars:%d\nChange:%d"),t_dollars,change;
return (0);
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The problem is with scanf and %c I changed it to a character array so that we can scan two initials easily and the code works.

#include<stdio.h>
int main()
{
char arr[2];
int pennies;
int nickels;
int dimes;
int quarters;
int loonies;
int change;
int t_dollars;
int t_cents;
printf("Type in your 2 initials and press return> ");
scanf("%s",arr);
printf("%s please enter in your coin information.\n",arr);
printf("Number of pennies>");
scanf("%d",&pennies);
printf("Number of nickels>");
scanf("%d",&dimes);
printf("Number of dimes>");
scanf("%d",&nickels);
printf("Number of quarters>");
scanf("%d",&quarters);
printf("Number of loonies>");
scanf("%d",&loonies);
t_cents=(1*pennies)+(5*nickels)+(10*dimes)+(25*quarters)+(100*loonies);
t_dollars=t_cents/100;
change=t_cents%100;
printf("Dollars:%d\nChange:%d",t_dollars,change);
return (0);
}

Add a comment
Know the answer?
Add Answer to:
I made this C program to count change and make a slip saying the exact dollar...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program that calculates exact change. In order to receive full credit, please remember...

    Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...

  • (In Python 3) Write a program with total change amount as an integer input, and output...

    (In Python 3) 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 So...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • C++ Write a program that helps a young student learn to make change. Use the random...

    C++ Write a program that helps a young student learn to make change. Use the random number generator to generate change amounts between1¢ and 99¢. Ask the user how many quarters, dimes, nickels and pennies they need to make that amount. Determine whether the coins specified by the user total the specified amount and give them feedback on their answer including whether they used the minimum or optimum number of coins to produce the amount. Sample output of a program...

  • I have this code for python: num = int(input()) if num == 0: print('No change') else:...

    I have this code for python: num = int(input()) if num == 0: print('No change') else: dol = num // 100 num %= 100 Quarters = num // 25 num %= 25 Dimes = num // 10 num %= 10 Nickels = num // 5 num %= 5 Pennies = num if dol > 0: if dol == 1: print('1 Dollar') if Dollars > 1: print(dol,'Dollars') if Quarters > 0: if Quarters == 1: print('1 Quarter') if Quarters > 1:...

  • *Create in Python 3: Change Calculator Create a program that calculates the coins needed to make...

    *Create in Python 3: Change Calculator Create a program that calculates the coins needed to make change for the specified number of cents. Sample Console Output Change Calculator   Enter number of cents (0-99): 99 Quarters: 3 Dimes: 2 Nickels: 0 Pennies: 4   Continue? (y/n): y Enter number of cents (0-99): 55   Quarters: 2 Dimes: 0 Nickels: 1 Pennies: 0   Continue? (y/n): n   Bye! Specifications The program should display the minimum number of quarters, dimes, nickels, and pennies that one needs...

  • HELP ( i get these comment for this assignment please help me to fixed Please do...

    HELP ( i get these comment for this assignment please help me to fixed Please do not ask user to enter cents.  Amount due and received should be in dollars such as 2.35 and 5.) Business P2.8Giving change. Implement a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer. Display the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return. #include <iostream>...

  • Describe how you would create a Python program that calculates the exact amount of change to...

    Describe how you would create a Python program that calculates the exact amount of change to give a customer in denominations of quarters, dimes, nickels, and pennies. For example, if the change is 79 cents, how many of each coin would be needed to give change?

  • it c++ coding. please write on atom software. 1. Write a program that converts dollars into coins a. Request a dolla...

    it c++ coding. please write on atom software. 1. Write a program that converts dollars into coins a. Request a dollar amount as an integer: $5.34 is input as 534 b. Use a constant variable to represent each coin as a fixed value: const int NICKEL 5; c. Use division and the mod function to calculate the number of each coin. Change Calculator Enter dollar amount (as an integer): $534 The equivalent in coins: 21 Quarters 0 Dimes 1 Nickels...

  • Given a value V in cents, you need to make change using a minimum number of...

    Given a value V in cents, you need to make change using a minimum number of coins. Assume you have an infinite supply of quarters, nickels, dimes, and pennies. Find the minimum number of coins. Display the quantity of each coin and the total number of coins, similar to the example output below. Use global constant identifiers, of type unsigned int, for the values of quarters, nickels, dimes, and pennies. Example: const unsigned int QUARTER = 25: Do not use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT