I've been browsing through some threads on this board and I ventured to a section in the faq about input flush. This topic interests me because I was having some trouble with validating user input. The section of code in the faq, however, will not work with my compiler. I was wondering if there were any alternatives to this. I will post the flush code first, and then my program I am working on. I am also using the crappy Miricle C complier.
This is the error I get: Parse Error, expecting `']'' or `NUMBER'Code:#include <stdio.h> int main(void) { int ch; char buf[BUFSIZ]; puts("Flushing input"); while ((ch = getchar()) != '\n' && ch != EOF); printf ("Enter some text: "); if (fgets(buf, sizeof(buf), stdin)) { printf ("You entered: %s", buf); } return 0; }
'char buf[BUFSIZ]'
Here is my code that I am working on
Code:#include <stdio.h> #include <ctype.h> int main(void)// main funtion with no parameters { int i = 0; char cArray[5][15] = { "1 Aus dollar", "2 Can dollar", "3 Euro", "4 Mex peso", "5 Swiss franc"}; char iSelection = '\0'; //initializes the menu selection float fCurrSelect = 0.00; //initializes the monetary value to be converted float fUSCurr = 0.00; //initializes the currency conversion do { //displays the title for program printf("\n\tCurrency Conversion Program 1.1\n\n"); printf("\nChoose the currency you wish to convert\n"); for (i=0; i<5; i++) printf("\n%s", cArray[i]); printf("\n\n"); scanf("%c", &iSelection); //stores the menu selection for conversion }while ( iSelection < '1' || iSelection > '5');//checks for valid input do { printf("\nHow much money would you like to convert to U.S. dollars?"); scanf("%f", &fCurrSelect); }while (fCurrSelect <= 0.0);//checks for valid currency amount //this begins the case switch for the menu selection switch(iSelection) { case '1': fUSCurr = (fCurrSelect/1.16686); printf("\nThe Austrailian dollar amount %.2f converted to USD equals $%.2f", fCurrSelect, fUSCurr); break; case '2': fUSCurr = (fCurrSelect/1.0072); printf("\nThe Canadian dollar amount %.2f converted to USD equals $%.2f", fCurrSelect, fUSCurr); break; case '3': fUSCurr = (fCurrSelect/0.695943); printf("\nThe Euro amount %.2f converted to USD equals $%.2f", fCurrSelect, fUSCurr); break; case '4': fUSCurr = (fCurrSelect/10.8509); printf("\nThe Mexican peso amount %.2f converted to USD equals $%.2f", fCurrSelect, fUSCurr); break; case '5': fUSCurr = (fCurrSelect/1.1522); printf("\nThe Swiss franc amount %.2f converted to USD equals $%.2f", fCurrSelect, fUSCurr); break; default: printf("\nInvalid option!"); }//end switch block getchar(); return 0; }//end main



LinkBack URL
About LinkBacks



