Advertisement
Lisaveta777

?

Aug 28th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 KB | None | 0 0
  1. #include <stdio.h>
  2. //broken now, once I've done it with functions!
  3. //from step 2, char choice working second time only, not first time!
  4. //something EXTRA in bufer or some other place messes up with everything!
  5.  
  6. //2 really basic functions,only to make sure,3that user didn't mess up, and input
  7. //char and float where he suppose to do so
  8. //without checking user's input it will be 6 or so lines long programm
  9. //
  10. char get_char(void);
  11. float  get_float (void);
  12.  
  13. int main()
  14. {
  15.     char ch;
  16.     float  fl;
  17.  
  18.     while((ch=get_char())!='q')
  19.     {
  20.         printf("in main %c\n",ch);
  21.         fl = get_float();
  22.         printf("in main %f\n",fl);
  23.     }
  24.  
  25.        return 0;
  26. }
  27. char get_char(void)
  28. {//input:38cn... - get rid of everything
  29.  //      cn... takes c, get rid of everything else
  30.  //      c     takes c, get rid of new line
  31.     char c;
  32.     printf("in func:Chose a,b,c or q?\n");
  33.     while((c=getchar())!= 'a' && c!='b' && c!='c' && c!='q')
  34.     {
  35.         while(getchar()!='\n') //when input is wrong
  36.               continue;
  37.        // printf("in func:Attention,input a,b,c
  38.  
  39.     }
  40.     while(getchar()!='\n') //when input is right
  41.         continue;
  42.         return c;
  43. }//end of get_char
  44.  
  45. float get_float(void)
  46. {
  47.     float amount;
  48.     int sc_res =0;
  49.     do
  50.     {
  51.         printf("how much of it do you want?\n");
  52.         sc_res = scanf("%f",&amount);
  53.         if(!sc_res)
  54.             scanf("%*s");
  55.     }while(!sc_res);
  56.     return amount;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement