Other than that I feel like an idiot, I'm having problems with my code for CS50's Get Cash program. There may be MANY errors still waiting, but currently the only error has to do with the sum of the 'remaining coins' in printf. (Program asks for user input as to an amount to give in change, converts it from float to int - and then calculates the least amount of coins to give as change)
First, I tried to share the printf with text and then the equation giving the sum of four integers following it. I thought I could add the integers and have the sum printed in printf - but no.
Second, I initialized 'sum' as an integer and did the math on a separate line - but when I tried to add sum after the text in printf, I would get this error:
error: data argument not used by format string
Which pointed at the printf line:
printf("Total Number of Coins for change:\n", sum); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
Here is the code:
/* this program is designed to give cashier the minimum number of coins to give as change after a purchase is made*/
include
include
int main(void) { float n = 0; int q, d, ni; int remd, remni, remp;
/* Require user input a number (float) representing an amount of change in coins to be returned. Number must be positive*/
do { printf("Enter amound of change to be returned: $"); n = get_float(); } while (n > 0);
/* The following code rounds off float 'n' to two digits and convert it to pennies from dollars and cents. Then it is converted into an integer*/
int i = n * 100;
/* The following are loops that will take integer 'i' and subtract first: quarters (int 'q'), second: dimes (int 'd' from the remainder) and third: nickels (int 'ni') and add them to the final remainder, which is the amount of pennies left, thus giving the least number of coins to give for change*/
while (i > 24) { q = i / 25; remd = i % 25; } while (remd > 9) { d = remd / 10; remni = remd % 10; } while (remni > 4) { ni = remni / 5; remp = remni % 5; }
/* finally - print the total number of coins to be given as change*/
/first, get the sum of the coins/ int sum=(q+d+ni+remp);
printf("Total Number of Coins for change:\n", sum);
return 0; }
Thanks so much for the help. I'm really trying to get a hang of this, but without an actual person to ask and bounce ideas off of, it is proving very difficult.
-singer