Advertisement
Lisaveta777

Short artishock fixed by while(getchar()...)

Aug 23rd, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. //why line 47 get duplicated? how to fix it?
  5. //fixed it by using while(ch=getchar)!='q'
  6. //how to fix it, if i use scanf for symbol?
  7.  
  8. int main()
  9. {
  10.      char ch;
  11.      float a,b,c,temp;//
  12.      a = b = c = temp = 0.0;
  13.  
  14.      printf("artishoks a\t\nbeetroot b\t");
  15.      printf("carrots c\t\nquit q\n");
  16.  
  17.      while( (ch=getchar())!='q' )
  18.      {
  19.         switch(ch)
  20.         {
  21.         case 'a':
  22.             {
  23.                 printf("How much of artishoks do you want?\n");
  24.                 scanf("%f",&temp);
  25.                 a+=temp;
  26.             }
  27.             break;
  28.         case 'b':
  29.             {
  30.                 printf("How much of beetroot do you want?\n");
  31.                 scanf("%f",&temp);
  32.                 b+=temp;
  33.             }
  34.             break;
  35.         case 'c':
  36.             {
  37.                 printf("How much of carrots do you want?\n");
  38.                 scanf("%f",&temp);
  39.                 c+=temp;
  40.             }
  41.             break;
  42.  
  43.         }//end of switch
  44.         printf("chose a,b,c,or q now\n");
  45.         while(getchar()!='\n')
  46.             continue;
  47.  
  48.         //scanf("%c",&ch);
  49.  
  50.      }//end of while
  51.  
  52.      return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement