this program works, but if I take out the while loop the program will end immediately after the last scanf(); I'm not sure why and would appreciate if someone could explain exactly why.
Code:#include <stdio.h> #define STORE_NAME "Sierra Sporting Goods" int main(void){ int intNumber, intType, intQuantity; double dblCost, dblPrice; printf("%s\n", STORE_NAME); printf("Enter the product number: "); scanf("%d", &intNumber); printf("\nEnter the product type: "); scanf("%d", &intType); printf("\nEnter the quantity: "); scanf("%d", &intQuantity); printf("\nEnter the cost: "); scanf("%lf", &dblCost); printf("\nEnter the price: "); scanf("%lf", &dblPrice); printf("\n\nThe product number is %d", intNumber); printf("\nThe product type is %d", intType); printf("\nThe quantity type is %d", intQuantity); printf("\nThe cost is %lf", dblCost); printf("\nThe price is %lf", dblPrice); printf("\nPress enter to continue\n"); while(getchar() != '\n'); /*clear the buffer*/ getchar(); return 0; }



LinkBack URL
About LinkBacks



