An online retailer sells five different products, whose retail prices are shown in
the following table:
Product number
Retail price
1
$2.98
2
$4.50
3
$9.98
4
$4.49
5
$6.87
Write a C program that reads a series of pairs of input as follows:
a.
Product number
b.
Quantity sold for one day
Write a program to help and determine the retail price for each product. Calculate
and display the total retail
value of all produ
#include <stdio.h>
int main() {
double price[5] = {2.98, 4.50, 9.98, 4.49, 6.87};
int product, num;
double totValue = 0.0;
printf("Enter product (1-5) number and quantity sold\n");
printf("Enter 0 to exit\n");
while (1) {
scanf("%d", &product);
if (product == 0) {
break;
}
scanf("%d", &num);
totValue += price[product-1] * num;
}
printf("The total retail value is $%.2lf\n", totValue);
return 0;
}
Comments
Leave a comment