Answer to Question #313805 in C for Suhani Goel

Question #313805

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



1
Expert's answer
2022-03-18T12:13:39-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS