c - Why won't this let me scan in my find and then unknown? -


so, trying make suvat solver (physics equations) , need read in need find(find) , thing don't know , won't need know (unknown). scans in find yet skips straight asking variables before asking unknown. why?

#include <stdio.h> #include <stdlib.h> #include <math.h>  int main (int argc, char *argv[]) { printf ("what trying find:\ndistance, inital velocity, final velocity, accelartion or time\n(enter first letter)\n"); char find; scanf("%c", &find); char unknown; printf ("what don't know: \n"); scanf("%c", &unknown);   int = 0; //initial velocity int f = 0; //final velocity int = 0; //accelaration int t = 0; //time int d = 0; //distance  if (((find != 'i') && (find != 'i')) && ((unknown != 'i') && (unknown != 'i'))){     printf("what inital velocity: \n");     scanf("%d", &i); } if (((find != 'd') && (find != 'd')) && ((unknown != 'd') && (unknown != 'd'))){     printf("what distance: \n");     scanf("%d", &d); } if (((find != 'f') && (find != 'f')) && ((unknown != 'f') && (unknown != 'f'))){     printf("what final velocity: \n");     scanf("%d", &f); } if (((find != 'a') && (find != 'a')) && ((unknown != 'a') && (unknown != 'a'))){     printf("what accelartion: \n");     scanf("%d", &a); } if (((find != 't') && (find != 't')) && ((unknown != 't') && (unknown != 't'))){     printf("what time: \n");     scanf("%d", &t); } //printf("find: %c, i: %d, f: %d, a: %d, d: %d, t: %d", find, i, f, a, d, t); if ((find == 'i') || (find == 'i')) {     if ((unknown == 's') || (unknown == 's')) {         = a*t - f;         printf("%d\n", i);     }     else if ((unknown == 'a') || (unknown == 'a')) {         = ((2*d)/t) - f;          printf("%d\n", i);     }     else if ((unknown == 't') || (unknown == 't')) {         = sqrt(pow(f,2)-(2*a*d));          printf("%d\n", i);     }     else if ((unknown == 'f') || (unknown == 'f')) {         = (d - (0.5*a*pow(t,2)))/t;         printf("%d\n", i);     } }     return exit_success; } 

scanf("%c", &find); 

should be

scanf(" %c", &find);    //  ^ space 

in program, scanf gets \n enter key press second char


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -