Advertisement
Lisaveta777

Prata artishoks

Aug 16th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #define APRICE 2.05
  5. #define BPRICE 1.15
  6. #define CPRICE 1.09
  7. #define DISCOUNT 0.05
  8. #define DELIV1 6.50
  9. #define DELIV2 14.00
  10.  
  11. //проблема - дважды печатает запрос выбора абся
  12. int main()
  13. {
  14.      char ch;
  15.      int flag = 1;
  16.      float a,b,c, temp;//
  17.      float total_weight, total_price, disc_price, deliv, final_price;
  18.      a = b = c = temp = 0.0;
  19.      printf("artishoks a\t");
  20.      printf("beetroot b\t");
  21.      printf("carrots c\t");
  22.      printf("quit q\n");
  23.      scanf("%c",&ch);
  24.      //scanf("%*[\n]");
  25.  
  26.      while( ch!='q' )
  27.      {
  28.         switch(ch)
  29.         {
  30.         case 'a':
  31.             {
  32.                 printf("How much of artishoks you want?\n");
  33.                 scanf("%f",&temp);
  34.                 a+=temp;
  35.             }
  36.             break;
  37.         case 'b':
  38.             {
  39.                 printf("How much of beetroot you want?\n");
  40.                 scanf("%f",&temp);
  41.                 b+=temp;
  42.  
  43.             }
  44.             break;
  45.         case 'c':
  46.             {
  47.                 printf("How much of carrots you want?\n");
  48.                 scanf("%f",&temp);
  49.                 c+=temp;
  50.  
  51.             }
  52.             break;
  53.         //default:
  54.             //printf("wrong choise, try again\n");
  55.  
  56.  
  57.         }//end of switch
  58.         //scanf("%*[\n]");
  59.         printf("chose a,b,c,or q now\n");
  60.         scanf("%c",&ch);
  61.         if(ch=='\n')
  62.         scanf("%*[\n]");
  63.  
  64.      }//end of while
  65.  
  66.      printf("you ask for %f art, %f bee, %f car\n",a,b,c);
  67.  
  68.      total_price = a*APRICE + b*BPRICE + c*CPRICE;
  69.  
  70.      if(total_price>=100.0)
  71.         disc_price = total_price*(1.0-DISCOUNT);
  72.      else
  73.         disc_price = total_price;
  74.  
  75.     total_weight = a+b+c;//delivery price
  76.     if(total_weight<=5.0)
  77.         deliv = DELIV1;
  78.     else if(total_weight<=20.0)
  79.         deliv = DELIV2;
  80.     else
  81.         deliv = DELIV2+(total_weight-20.0)*0.5;
  82.  
  83.         final_price = disc_price+ deliv;
  84.  
  85.         printf("total weight is %f, total price is %f, deliv is %f\n",total_weight,total_price,deliv);
  86.         printf("disc price is %f\n",disc_price);
  87.         printf("final price is %f\n",final_price);
  88.         printf("delivery is %f",deliv);
  89.  
  90.  
  91.      return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement