This code works exactly like I expect by itself:
But in my program seen next it is skipping reading in the R but the N is read in fine.Code:#include <stdio.h> int main() { char reqOrSugg, oldOrNew; printf ("\nIs This Textbook Required Or Suggested?\n"); printf ("Enter R for Required or S for Suggested:\n"); reqOrSugg = getchar(); while (getchar() != '\n'); printf ("Is This Textbook Old Or New?\n"); printf ("Enter O for old or N for new:\n"); oldOrNew = getchar(); while (getchar() != '\n'); printf ("%c%s",reqOrSugg,"\n"); printf ("%c%s",oldOrNew,"\n"); return 0; }
Can anyone explain this to me and tell me how to correct this? I suspect it has something to do with the new lines. I cant get the if/else to work without this working first. TyCode:~ printf ("\nPlease Enter The Expected Enrollment: \n"); scanf ("%lf", &expectedEn); printf ("%1.0lf%s",expectedEn,"\n"); printf ("\nIs This Textbook Required Or Suggested?\n"); printf ("Enter R for Required or S for Suggested:\n"); reqOrSugg = getchar(); while (getchar() != '\n'); printf ("Is This Textbook Old Or New?\n"); printf ("Enter O for old or N for new:\n"); oldOrNew = getchar(); while (getchar() != '\n'); printf ("%c%s",reqOrSugg,"\n"); printf ("%c%s",oldOrNew,"\n"); if (reqOrSugg == 'R' || oldOrNew == 'N') { numToOrd = expectedEn * .9; } ~
Justin



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.