Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define APRICE 2.05
- #define BPRICE 1.15
- #define CPRICE 1.09
- #define DISCOUNT 0.05
- #define DELIV1 6.50
- #define DELIV2 14.00
- //проблема - дважды печатает запрос выбора абся
- int main()
- {
- char ch;
- int flag = 1;
- float a,b,c, temp;//
- float total_weight, total_price, disc_price, deliv, final_price;
- a = b = c = temp = 0.0;
- printf("artishoks a\t");
- printf("beetroot b\t");
- printf("carrots c\t");
- printf("quit q\n");
- scanf("%c",&ch);
- //scanf("%*[\n]");
- while( ch!='q' )
- {
- switch(ch)
- {
- case 'a':
- {
- printf("How much of artishoks you want?\n");
- scanf("%f",&temp);
- a+=temp;
- }
- break;
- case 'b':
- {
- printf("How much of beetroot you want?\n");
- scanf("%f",&temp);
- b+=temp;
- }
- break;
- case 'c':
- {
- printf("How much of carrots you want?\n");
- scanf("%f",&temp);
- c+=temp;
- }
- break;
- //default:
- //printf("wrong choise, try again\n");
- }//end of switch
- //scanf("%*[\n]");
- printf("chose a,b,c,or q now\n");
- scanf("%c",&ch);
- if(ch=='\n')
- scanf("%*[\n]");
- }//end of while
- printf("you ask for %f art, %f bee, %f car\n",a,b,c);
- total_price = a*APRICE + b*BPRICE + c*CPRICE;
- if(total_price>=100.0)
- disc_price = total_price*(1.0-DISCOUNT);
- else
- disc_price = total_price;
- total_weight = a+b+c;//delivery price
- if(total_weight<=5.0)
- deliv = DELIV1;
- else if(total_weight<=20.0)
- deliv = DELIV2;
- else
- deliv = DELIV2+(total_weight-20.0)*0.5;
- final_price = disc_price+ deliv;
- printf("total weight is %f, total price is %f, deliv is %f\n",total_weight,total_price,deliv);
- printf("disc price is %f\n",disc_price);
- printf("final price is %f\n",final_price);
- printf("delivery is %f",deliv);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement