I can't understand why input '-' or '+' jump to display no record found.Code:#include <stdio.h> #include <stdlib.h> int main() { int stop, ch, valid = 0; do { // display title printf("Individual Salesman Commission\n"); printf("==============================\n"); // prompt and read salesman id printf("Salesman ID (NO.): "); scanf("%d", &stop); // Only give user to pass if it is number while ( (ch = getchar()) != '\n') { // if it is not valid input if(ch > 1) { while ( (ch = getchar()) != '\n'); printf("Invalid input. Please input again...\n"); getchar(); system("cls"); // display title printf("Individual Salesman Commission\n"); printf("==============================\n"); // prompt and read salesman id printf("Salesman ID (NO.): "); scanf("%d", &stop); } // end if } // end while valid = 1; // end loop process // clear screen display system("cls"); } while (valid == 0); // loop if the input is invalid if(stop <= 0 ) { // Display error message printf("No record found.\n"); } // end else printf("Press Enter to exit program...\n"); getchar(); } // end function main



4Likes
LinkBack URL
About LinkBacks





