-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chapter4-Q19.c
111 lines (85 loc) · 2.79 KB
/
Chapter4-Q19.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
Author is : Ibrahim Halil GEZER
4.19 (Calculating Sales) An online retailer sells five different products whose retail prices are
shown in the following table:
Product Retail price
number
1 $ 2.98
2 $ 4.50
3 $ 9.98
4 $ 4.49
5 $ 6.87
Write a program that reads a series of pairs of numbers as follows:
a) Product number
b) Quantity sold for one day
Your program should use a switch statement to help determine the retail price for each product.
Your program should calculate and display the total retail value of all products sold last week.
*/
#include <stdio.h>
#include<stdbool.h>
int main ()
{
int product1 =0 , product2 =0 , product3 =0 , product4 =0 , product5 =0 ;
int sales1 =0, sales2 =0, sales3 =0, sales4 =0, sales5 =0 ;
int i ,number ;
printf( "Enter product number: 1 to 5 \n" ) ;
printf ( "Enter the EOF character to end \n" );
//scanf ("%d", &number);
while (( number = getchar()) != EOF ) { // while begins
switch ( number ) {
case '1' :
// produc1++ ;
printf ( "How many product 1 you sell ? " ) ;
scanf ("%d",&i);
sales1 += i ;
printf( "\nEnter product number: 1 to 5 \n" ) ;
break ;
case '2' :
// product2++ ;
printf ( "How many product 2 you sell ? " ) ;
scanf ("%d",&i);
sales2 += i ;
i =0 ;
printf( "\nEnter product number: 1 to 5 \n" ) ;
break ;
case '3' :
// product1++ ;
printf ( "How many product 3 you sell ? " ) ;
scanf ("%d",&i);
sales3 += i ;
i =0 ;
printf( "\nEnter product number: 1 to 5 \n" ) ;
break ;
case '4':
// produc1++ ;
printf ( "How many product 4 you sell ? " ) ;
scanf ("%d",&i);
sales4 += i ;
i =0 ;
printf( "\nEnter product number: 1 to 5 \n" ) ;
break ;
case '5' :
// produc1++ ;
printf ( "How many product 5 you sell ? " ) ;
scanf ("%d",&i);
sales5 += i ;
i =0 ;
printf( "\nEnter product number: 1 to 5 \n" ) ;
break ;
case '\n' :
case ' ' :
case '\t' :
break ;
default :
printf ("Incorrect ýnput entered !\n");
printf ("Enter new number: \n" ) ;
break ;
} // end swicth case
} // end while
printf ( "Total sales of product 1 is %d and total retail value is $%.2f\n",sales1, (float)sales1*2.98 ) ;
printf ( "Total sales of product 2 is %d and total retail value is $%.2f\n",sales2, (float)sales2*4.50 ) ;
printf ( "Total sales of product 3 is %d and total retail value is $%.2f\n",sales3, (float)sales3*9.98) ;
printf ( "Total sales of product 4 is %d and total retail value is $%.2f\n",sales4, (float)sales4*4.49 ) ;
printf ( "Total sales of product 5 is %d and total retail value is $%.2f\n",sales5, (float)sales5*6.87 ) ;
return 0 ;
} // end function main