D
Dino000121
Guest
So the project is I am super stumped on. I got pretty far into it and i thought I was done, Only to see that my answers are completely off. Because Im new to this i did not even know what forum to post it to. I wrote my program in basic C language. This was my assignment... "Your project will act like an ATM dispensing the correct amount of charge starting with the highest denomination and working down. For the project we'll be using $20's, $10's, $5's, $1's, quarters, dimes, nickels, and pennies. The program will ask for amount from the user (>=0 AND <= $100) and you job is to print out change to dispense following by the original amount requested in the format shown below."
So far I have this...
#include <stdio.h>
#define startingSize 100
int main(void) {
float amount;
printf("Please enter amount to dispense in $$.$$ form (dollars.cents): ");
scanf("%f",&amount);
printf("ATM processing...\nATM preforming withdrawal...\n");
int dollars=amount;
float remaining=(amount-dollars)*100;
//Cash
int twenties=remaining/20;
remaining=remaining-twenties*20;
int tens=remaining/10;
remaining=remaining-tens*10;
int fives=remaining/5;
remaining=remaining-fives*5;
int ones=remaining/1;
remaining=remaining-ones*1;
//Coins
int quarters=remaining/.25;
remaining=remaining-quarters*.25;
int dimes=remaining/.10;
remaining=remaining-dimes*.10;
int nickels=remaining/.05;
remaining=remaining-nickels*.05;
int pennies=remaining/.01;
remaining=remaining-pennies*.01;
//Cash
if(twenties!=0)
printf("%d Twenties\n",twenties);
if(tens!=0)
printf("%d Tens\n",tens);
if(tens!=0)
printf("%d Fives\n",fives);
if(ones!=0)
printf("%d Ones\n",ones);
//Coin
if(quarters!=0)
printf("%d Quarters\n",quarters);
if(dimes!=0)
printf("%d Dimes\n",dimes);
if(nickels!=0)
printf("%d Nickels\n",nickels);
if(pennies!=0)
printf("%d Pennies\n",pennies);
printf("----------------------\n");
printf("| Twenties | %d |\n", twenties);
printf("| Tens | %d |\n", tens);
printf("| Fives | %d |\n", fives);
printf("| Ones | %d |\n", ones);
printf("| Quarters | %d |\n", quarters);
printf("| Dimes | %d |\n", dimes);
printf("| Nickles | %d |\n", nickels);
printf("| Pennies | %d |\n", pennies);
printf("-------------------\n");
printf("| Dispensed | $%7.2f |\n", amount);
printf("----------------------\n");
return 0;
}
Then to test it, I put in $34.41, so I have 1 of everything for the Cash value and the coin value. However, when I do that, i . get this....
Please enter amount to dispense in $$.$$ form (dollars.cents): 36.41
ATM processing...
ATM preforming withdrawal...
2 Twenties
3 Quarters
2 Dimes
4 Pennies
----------------------
| Twenties | 2 |
| Tens | 0 |
| Fives | 0 |
| Ones | 0 |
| Quarters | 3 |
| Dimes | 2 |
| Nickels | 0 |
| Pennies | 4 |
-------------------
| Dispensed | $ 36.41 |
----------------------
This obviously is not right because of instead of showing 1 for every variable, it is giving me a total of only $40.99. Can anyone help me figure out what I did wrong? I am really new to this and can use all the help I can get.
Thanks.
Continue reading...
So far I have this...
#include <stdio.h>
#define startingSize 100
int main(void) {
float amount;
printf("Please enter amount to dispense in $$.$$ form (dollars.cents): ");
scanf("%f",&amount);
printf("ATM processing...\nATM preforming withdrawal...\n");
int dollars=amount;
float remaining=(amount-dollars)*100;
//Cash
int twenties=remaining/20;
remaining=remaining-twenties*20;
int tens=remaining/10;
remaining=remaining-tens*10;
int fives=remaining/5;
remaining=remaining-fives*5;
int ones=remaining/1;
remaining=remaining-ones*1;
//Coins
int quarters=remaining/.25;
remaining=remaining-quarters*.25;
int dimes=remaining/.10;
remaining=remaining-dimes*.10;
int nickels=remaining/.05;
remaining=remaining-nickels*.05;
int pennies=remaining/.01;
remaining=remaining-pennies*.01;
//Cash
if(twenties!=0)
printf("%d Twenties\n",twenties);
if(tens!=0)
printf("%d Tens\n",tens);
if(tens!=0)
printf("%d Fives\n",fives);
if(ones!=0)
printf("%d Ones\n",ones);
//Coin
if(quarters!=0)
printf("%d Quarters\n",quarters);
if(dimes!=0)
printf("%d Dimes\n",dimes);
if(nickels!=0)
printf("%d Nickels\n",nickels);
if(pennies!=0)
printf("%d Pennies\n",pennies);
printf("----------------------\n");
printf("| Twenties | %d |\n", twenties);
printf("| Tens | %d |\n", tens);
printf("| Fives | %d |\n", fives);
printf("| Ones | %d |\n", ones);
printf("| Quarters | %d |\n", quarters);
printf("| Dimes | %d |\n", dimes);
printf("| Nickles | %d |\n", nickels);
printf("| Pennies | %d |\n", pennies);
printf("-------------------\n");
printf("| Dispensed | $%7.2f |\n", amount);
printf("----------------------\n");
return 0;
}
Then to test it, I put in $34.41, so I have 1 of everything for the Cash value and the coin value. However, when I do that, i . get this....
Please enter amount to dispense in $$.$$ form (dollars.cents): 36.41
ATM processing...
ATM preforming withdrawal...
2 Twenties
3 Quarters
2 Dimes
4 Pennies
----------------------
| Twenties | 2 |
| Tens | 0 |
| Fives | 0 |
| Ones | 0 |
| Quarters | 3 |
| Dimes | 2 |
| Nickels | 0 |
| Pennies | 4 |
-------------------
| Dispensed | $ 36.41 |
----------------------
This obviously is not right because of instead of showing 1 for every variable, it is giving me a total of only $40.99. Can anyone help me figure out what I did wrong? I am really new to this and can use all the help I can get.
Thanks.
Continue reading...