My professor asked for us to use 2 loops. it was in the problem i had on here yesterday but i did away with it due to complaints.
here is the complete code, im getting crazy numbers back for change due.
Code:
#include <stdio.h>
int main()
{
int numItems;
float price, amtPaid, total = 0, change;
int quarters = 10, dimes = 10, nickels = 10, pennies = 10;
printf("Please enter the number of grocery items>");
scanf("%d", &numItems);
while (numItems != 0)
{
/* Begin while loop*/
while (numItems != 0)
{
printf("Please enter the price for your item>");
scanf("%f", &price);
total += price;
numItems--;}
}
printf("\nPlease enter the amount paid>");
scanf("%f", &amtPaid);
change = amtPaid - total;
printf("change is %.2f\n", change);
quarters = change / .25;
dimes = change / .10;
nickels = change / .05;
pennies = change / .01;
printf("The coins returned are:\n %d Quarters \n %d
Dimes \n %d Nickels \n%d Pennies.\n", quarters, dimes, nickels, pennies);
total = 0;
printf("\n\nPlease enter the number of grocery items>");
scanf("%d", &numItems);
} /*end while loop*/
return 0;
} /*end function main*/