I am having trouble with a loop. i can get the program to ask for the quantity and compute the same price for a certain amount of items, but i need it to loop and ask for the price of number(n) of items input by the user. it needs to be set up where they enter a number of items (n)and the program lets them enter the prices on that certain amount of items (n). can someone pease give me a little help with the loop. i used notes and slides i was given in class to do what i have so far but he hasnt really gone over loops that much and im new to programming.
Code:/* Cash register simulator with change machine */ #include <stdio.h> #include <stdlib.h> int main( void ) { int items; /* item qty purchased */ double price; /* item price */ double itemTotal; /* item total price */ double total = 0; /* customer total bill */ double amtPaid; /* amount paid by customer */ double change; /* change due customer */ int centsLeft; /* cents left to pay in change */ printf(" checkout line\n\n" "Enter 0 for items to see total bill.\n\n"); printf("enter number of items: "); /* input */ scanf("%d", &items); while( items != 0 ) { printf("Price: "); scanf("%lf", &price); itemTotal = items * price; printf("Item total: %.2f", itemTotal); /* display totals */ total += itemTotal; /* add to total bill */ printf("\n\nenter number of items: "); /* working input */ scanf("%d", &items); } printf("\n--------------------------\n"); /* totals */ printf("Customer total: %8.2f\n", total); printf("Total due: %8.2f\n\n", total ); printf("\n\n"); system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks


