I had to modify my code to accept when invalid data would be entered, it will now print invalid data entered, but it skips an entire section of my if/else statement?
It just says:Code:#include <stdio.h> #define P 10.50 #define PMON 12.50 #define PPRIN 13.50 #define PMP 15.00 #define PII 15.50 #define PIIMON 18.50 #define PIIPRIN 19.00 #define PIIMP 21.00 main() { char comptype, rentmon, rentprint; int rentdays; double totamnt, rate; printf("\nEnter type of computer rented (S=Pentium or P=Pentium II) : "); scanf("%c", &comptype); if (comptype == 'S' || comptype == 's' || (comptype == 'P' || comptype == 'p')) { printf("\nWas a monitor rented? : "); getchar(); rentmon = getchar(); if (rentmon == 'Y' || rentmon == 'y' || (rentmon == 'N' || rentmon == 'n')) { printf("\nWas a printer rented? : "); getchar(); rentprint = getchar(); if (!(rentprint == 'Y' || rentprint == 'y' || rentprint == 'N' || rentprint == 'n')) { printf("\nInvalid data entered\n"); } else { if (comptype == 'S' || (comptype == 's')) { if (rentmon == 'Y' || (rentmon == 'y')) { if (rentprint == 'Y' || (rentprint == 'y')) { rate = PMP; } else { rate = PMON; } } else { (rentmon == 'N' || (rentmon == 'n')); if (rentprint == 'Y' || (rentprint == 'y')) { rate = PPRIN; } else { rate = P; } } } else { (comptype == 'P' || (comptype == 'p')); if (rentmon == 'Y' || (rentmon == 'y')) { if (rentprint == 'Y' || (rentprint == 'y')) { rate = PIIMP; } else { rate = PIIMON; } } else { (rentmon == 'N' || (rentmon == 'n')); if (rentprint == 'Y' || (rentprint == 'y')) { rate = PIIPRIN; } else { rate = PII; } } } } } else { printf("\nInvalid data entered\n"); } } else { printf("\nInvalid data entered\na"); } }
Was a monitor rented? : y
was a printer rented? : y
and then just says hit any key to continue
I think the problem is related somewhere in this area
Code:if (!(rentprint == 'Y' || rentprint == 'y' || rentprint == 'N' || rentprint == 'n')) { printf("\nInvalid data entered\n"); } else { if (comptype == 'S' || (comptype == 's')) { if (rentmon == 'Y' || (rentmon == 'y'))




Reply With Quote