c - code runs, but says invalid -


when run program asks command, when type in a, b, or c prompts give letter based on chose value. other command listed displays statistics. small issue when type in valid command, "invalid command" warning pops up, though works

#include <stdio.h>  int main(void) {    double = 0;    double b = 0;    double c = 0;    double d = 0;    double e = 0;    double f = 0;    double g = 0;    double h = 0;    double = 0;     char command = '\0';     printf("\n      welcome\n");    printf("     aquapodz stress analysis program\n");    printf("    ==================================\n");    while (command != 'x');    {       printf("\n\n(a), (b), or (c), enter trial data        vendor.\n(f)ail-rate,     (m)ean stress, (s)ummary, e(x)it\n");       printf("please enter command");       scanf("%c", &command);        if (command == 'a')       {          printf("please enter stress values (gpa) trial.");          scanf("%lf", &a);          scanf("%lf", &b);          scanf("%lf", &c);       }       else if (command == 'b')       {          printf("please enter stress values (gpa) trial.");          scanf("%lf", &d);          scanf("%lf", &e);          scanf("%lf", &f);       }       else if (command == 'c')       {          printf("please enter stress values (gpa) trial.");          scanf("%lf", &g);          scanf("%lf", &h);          scanf("%lf", &i);       }       else if (command == 'f')       {           printf("average failure rate:\nazuview:%f\nbublon:%f    \ncryztal:%f\n",        a+b+c, d+e+f, g+h+i);       }       else if (command == 'm')       {          printf("average mean stress:\nazuview:%f\nbublon:%f\ncryztal:%f\n",         a+b+c/3, d+e+f/3, g+h+i/3);       }       else if (command == 's')       {          print("total (pass / fail) far:\nazuview:%f(%f/0)\nbublon:%f(%f/0)        \ncryztal:%f(%f/0)\n", a+b+c, a+b+c, d+e+f, d+e+f, g+h+i, g+h+i);       }       else if (command == 'x')       {        }       else       {          printf("invalid command! please try again :)");       }     }    printf("goodbye, please come again!");    return 0; } 

  scanf("%c", &command); 

is problem. end reading newline character left on previous call scanf. use

  scanf(" %c", &command); 

Comments