How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask ATLPROG Your Own Question

ATLPROG
ATLPROG, Computer Software Engineer
Category: Programming
Satisfied Customers: 9151
Experience:  MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
44910485
Type Your Programming Question Here...
ATLPROG is online now
A new question is answered every 9 seconds

I am new to C programming, and this is an assignment problem.

This answer was rated:

I am new to C programming, and this is an assignment problem. I have no idea how to accomplish this.


Call the function change() from main() three times and print out the contents of the variables quarters, dimes, nickels, and pennies after each function return.
First Call--pass in the total value $1.88 and on return print the contents of the variables.
Second Call--pass in the total value .32 and on return print the contents of the variables.
Third Call--ask for a total value input from the keyboard and on return print the contents of the variables.

Output should look like:
TOTAL VALUE ENTERED: 1.88
7 quarters
1 dime
0 nickels
3 pennies
and not:
TOTAL VALUE ENTERED: 1.88
7 quarters
18 dimes
37 nickels
188 pennies

ATLPROG : Hi welcome. I will have this ready soon
ATLPROG :

Hello

ATLPROG :

Please confirm if you still need assistance with this

Customer:

Yes, I still need help with this. The website was having problems when I tried to submit it this morning.

Customer:

Hello?

ATLPROG :

Sorry for that..

ATLPROG :

i will have this ready soon

Customer:

I have some code that mostly works.


#include <stdio.h>



int change(float total, int *quarters, int *dimes, int *nickels, int *pennies);


void print(float total, int quarters, int dimes, int nickels, int pennies);




int main(void)


{


int quarters, dimes, nickels, pennies;


float total;






printf("This program will give the coins required for two fixed values, and one user input value.\n");






total = 1.88;


change(total, &quarters, &dimes, &nickels, &pennies); //for the first call to change, calculates for defined value of 1.88


print(total, quarters, dimes, nickels, pennies);



total = 0.32;


change(total, &quarters, &dimes, &nickels, &pennies); //for the second call, calculates for defined value of 0.32


print(total, quarters, dimes, nickels, pennies);






printf("\nPlease enter an amount of money: "); //This gets the users input for the amount to make change for.


scanf("%f", &total);






change(total, &quarters, &dimes, &nickels, &pennies); //calls the function change() to calculate for the user input





print(total, quarters, dimes, nickels, pennies); //prints the user input values for change






fflush(stdin); /* clear input area so you can pause */


printf("Press the key to exit program.");


getchar(); /* force the computer to pause until you press a key on the keyboard */




return 0;


}





int change(float total, int *quarters, int *dimes, int *nickels, int *pennies) //declares the variables for the change function




{







if( total >= 0.25 )


*quarters = (total / 0.25); //calculates the amount of quarters, and stores it into quarters


if( total >= 0.10 )


*dimes = (total - (*quarters * 0.25)) / 0.10; //calculates the amount of dimes, and stores it into dimes


if( total >= 0.05 )


*nickels = (total - (*quarters * 0.25) - (*dimes * 0.10)) / 0.05; //calculates the amount of nickels, and stores it into nickels


if( total >= 0.01 )


*pennies = (total - (*quarters * 0.25) - (*dimes * 0.10) - (*nickels * 0.05)) / 0.01 + .005; //calculates the amount of pennies, and stores it into pennies








return 0;


}



void print(float total, int quarters, int dimes, int nickels, int pennies)


{


printf("\nTOTAL VALUE ENTERED: $%.2f", total);


printf("\n%3d quarters\n", quarters);


printf("\n%3d dimes\n", dimes);


printf("\n%3d nickels\n", nickels);


printf("\n%3d pennies\n", pennies);

Customer:

I have some code that mostly works. The only thing is that it doesn't work for values below 0.32 What am I doing wrong?


#include <stdio.h>



int change(float total, int *quarters, int *dimes, int *nickels, int *pennies);


void print(float total, int quarters, int dimes, int nickels, int pennies);




int main(void)


{


int quarters, dimes, nickels, pennies;


float total;






printf("This program will give the coins required for two fixed values, and one user input value.\n");






total = 1.88;


change(total, &quarters, &dimes, &nickels, &pennies); //for the first call to change, calculates for defined value of 1.88


print(total, quarters, dimes, nickels, pennies);



total = 0.32;


change(total, &quarters, &dimes, &nickels, &pennies); //for the second call, calculates for defined value of 0.32


print(total, quarters, dimes, nickels, pennies);






printf("\nPlease enter an amount of money: "); //This gets the users input for the amount to make change for.


scanf("%f", &total);






change(total, &quarters, &dimes, &nickels, &pennies); //calls the function change() to calculate for the user input





print(total, quarters, dimes, nickels, pennies); //prints the user input values for change






fflush(stdin); /* clear input area so you can pause */


printf("Press the key to exit program.");


getchar(); /* force the computer to pause until you press a key on the keyboard */




return 0;


}





int change(float total, int *quarters, int *dimes, int *nickels, int *pennies) //declares the variables for the change function




{







if( total >= 0.25 )


*quarters = (total / 0.25); //calculates the amount of quarters, and stores it into quarters


if( total >= 0.10 )


*dimes = (total - (*quarters * 0.25)) / 0.10; //calculates the amount of dimes, and stores it into dimes


if( total >= 0.05 )


*nickels = (total - (*quarters * 0.25) - (*dimes * 0.10)) / 0.05; //calculates the amount of nickels, and stores it into nickels


if( total >= 0.01 )


*pennies = (total - (*quarters * 0.25) - (*dimes * 0.10) - (*nickels * 0.05)) / 0.01 + .005; //calculates the amount of pennies, and stores it into pennies








return 0;


}



void print(float total, int quarters, int dimes, int nickels, int pennies)


{


printf("\nTOTAL VALUE ENTERED: $%.2f", total);


printf("\n%3d quarters\n", quarters);


printf("\n%3d dimes\n", dimes);


printf("\n%3d nickels\n", nickels);


printf("\n%3d pennies\n", pennies);

I will provide answer soon
Customer: replied 3 years ago.

You never answered my question.

I thought i did..please download solution from
http://wikisend.com/download/130442/ChangeCoins.c

I hope i was able to assist you. If you are happy with my service please rate my service . If your are not 100% satisfied, please reply to me so that i can help you better. Please start your question with "For ATLProg only" to request me again
ATLPROG and other Programming Specialists are ready to help you
Customer: replied 3 years ago.

You didn't send me the link to download it until now.

Sorry for that..did you get it now?
Customer: replied 3 years ago.

Yes, I had to turn in my assignment without it though.

We have website issues on that day and i thought i had posted the link but looks like it didnt post it properly back then. Sorry for that

Related Programming Questions