this grocery checkout line simulator compiles and tells me syntax error 'return' i cant figure that out . but the big problem is my program gets all the way to the point where it tells the user the amount of change, but then it aborts because it says the variable centsLeft is being used without being defined...can anyone help me.
Code:#include <stdio.h> #include <stdlib.h> int main() { /* Begin function main*/ int numItems; int price, amtPaid, total = 0, change; int quarters = 10, dimes = 10, nickels = 10, pennies = 10; int centsLeft = 100 * change ; // cents left to pay in change 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); if( change > 0 ) // optional denomination breakdown { centsLeft = 100 * change; // convert to integer cents, // and make sure not to // truncate last cent if( centsLeft >= 2000 ) { printf(" $20 - %d\n", centsLeft / 2000); centsLeft -= 2000 * ( centsLeft / 2000 ); } if( centsLeft >= 1000 ) { printf(" $10 - %d\n", centsLeft / 1000); centsLeft -= 1000 * ( centsLeft / 1000); } if( centsLeft >= 500 ) { printf(" $ 5 - %d\n", centsLeft / 500); centsLeft -= 500 * ( centsLeft / 500 ); } if( centsLeft >= 100 ) { printf(" $ 1 - %d\n", centsLeft / 100); centsLeft -= 100 * ( centsLeft / 100 ); } if( centsLeft >= 25 ) { printf(" 25%c - %d\n", 155, centsLeft / 25); // 155 is ASCII code centsLeft -= 25 * ( centsLeft / 25 ); // for cent symbol } // in Win TERMINAL if( centsLeft >= 10 ) // character set { printf(" 10%c - %d\n", 155, centsLeft / 10); centsLeft -= 10 * ( centsLeft / 10 ); } if( centsLeft >= 5 ) { printf(" 5%c - %d\n", 155, centsLeft / 5); centsLeft -= 5 * ( centsLeft / 5 ); } if( centsLeft > 0 ) { printf(" 1%c - %d", 155, centsLeft); } } printf("\n\n"); } total = 0; printf("\n\nPlease enter the number of grocery items>"); scanf("%d", &numItems); } /*end while loop*/ return 0; /*end function main*/



LinkBack URL
About LinkBacks


