1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <stdio.h>
#include <stdlib.h>
int main(){
float product1,product2,product3,product4,product5; // calculator for products' prices
int product,quantity,day; // product is a sentinel value
float sum=0;
float price1=2.98,
price2=4.50,
price3=9.98,
price4=4.49,
price5=6.87;
printf("%s%20s\n","PRODUCT NUMBER","RETAIL PRICE");
printf("1%25.2f\n",price1);
printf("2%25.2f\n",price2);
printf("3%25.2f\n",price3);
printf("4%25.2f\n",price4);
printf("5%25.2f",price5);
for(day=1;day<=7;day++){
product1=product2=product3=product4=product5=1;
product=0;
printf("\n\n*********** Day %d ***********\n\n",day);
while(product!=EOF){
printf("Enter product number(EOF to exit): ");
scanf("%d",&product);
if(product!=EOF){
printf("Enter quantity sold for one day: ");
scanf("%d",&quantity);
switch(product){
case 1:
product1=1.*quantity*price1;
break;
case 2:
product2=1.*quantity*price2;
break;
case 3:
product3=1.*quantity*price3;
break;
case 4:
product4=1.*quantity*price4;
break;
case 5:
product5=1.*quantity*price5;
break;
}
}
}
sum+=(product1+product2+product3+product4+product5);
}
printf("Total retail for last week: %.2f",sum);
return 0;
}
|