Question

This is in C.

4.19 (Calculating Sales) An online retailer sells five different products whose retail prices are shown in the following tabl

Sample input and output Please enter the product number between 1 and 5. -1 to end : 1 Please enter quantity sold: 2 Please e

Please enter the product number between 1 and 5. -1 to end :5 Please enter quantity sold: 7 Please enter the product number b

0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

If you have any doubts, please give me comment...

#include<stdio.h>

int main(){

int prod_no, quantity;

int prod1_qty=0, prod2_qty=0, prod3_qty=0, prod4_qty=0, prod5_qty=0;

double prod1_sales=0, prod2_sales=0, prod3_sales=0, prod4_sales=0, prod5_sales=0;

double total = 0.0;

printf("Please enter the product number between 1 and 5. -1 to end: ");

scanf("%d", &prod_no);

while(prod_no!=-1){

printf("Please enter quantity sold: ");

scanf("%d", &quantity);

switch(prod_no){

case 1:

prod1_qty += quantity;

prod1_sales += quantity*2.98;

break;

case 2:

prod2_qty += quantity;

prod2_sales += quantity*4.50;

break;

case 3:

prod3_qty += quantity;

prod3_sales += quantity*9.98;

break;

case 4:

prod4_qty += quantity;

prod4_sales += quantity*4.49;

break;

case 5:

prod5_qty += quantity;

prod5_sales += quantity*6.87;

break;

}

printf("Please enter the product number between 1 and 5. -1 to end: ");

scanf("%d", &prod_no);

}

total = prod1_sales + prod2_sales + prod3_sales + prod4_sales + prod5_sales;

printf("Product\t\tQty\tSales\n");

printf("Product 1:\t%d\t%.2f\n", prod1_qty, prod1_sales);

printf("Product 2:\t%d\t%.2f\n", prod2_qty, prod2_sales);

printf("Product 3:\t%d\t%.2f\n", prod3_qty, prod3_sales);

printf("Product 4:\t%d\t%.2f\n", prod4_qty, prod4_sales);

printf("Product 5:\t%d\t%.2f\n", prod5_qty, prod5_sales);

printf("\nTotal\t: %.2f\n", total);

return 0;

}

nagarajuanagaraju-Vostro-3550:10022020$ gcc sales. nagarajuanagaraju-Vostro-3550: 10022020$ ./a.out Please enter the product

Add a comment
Know the answer?
Add Answer to:
This is in C. 4.19 (Calculating Sales) An online retailer sells five different products whose retail...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • A mail order house sells five different products whose retail prices are: product 1: $2.98 product...

    A mail order house sells five different products whose retail prices are: product 1: $2.98 product 2: $4.50 product 3: $9.98 product 4: $4.49 product 5: $6.87. Write a program that reads a series of pairs of numbers as follows: a) product number b) quantity sold Your program should use a switch statement to determine the retail price for each product. Your program should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to...

  • Amail-order housesellsfivedifferentproductswhoseretailpricesareasfollows:product1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49; and product 5, $6.87....

    Amail-order housesellsfivedifferentproductswhoseretailpricesareasfollows:product1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49; and product 5, $6.87. Write a script that reads a series of pairs of numbers as follows: a) Product number b) Quantity sold for one day(html)

  • Programming language C. A small U-Pick farm sells five different U-Pick citrus fruit products whose retail...

    Programming language C. A small U-Pick farm sells five different U-Pick citrus fruit products whose retail prices are: 1. Sugarbells - $1.99/lb, 2. Honeybells - $2.39/lb, 3. Red Grapefruit $1.69/lb, 4. Navel Oranges - $1.49/lb, 5. Pomelo - $1.89/lb. Write a program that allows the user to select one or more products, input the weights of each product, and calculate the total amount due. The farm only accepts cash. Your program will take input of the cash received and calculate...

  • Write a Java application that prompts the user for pairs of inputs of a product number...

    Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (this is two separate prompts for input values). You must use a switch statement and a sentinel-controlled loop (i.e. a loop that stops execution when an out of range value, such as -1, is input). All 15 items below are for a single purchase. There are five sets of inputs as follows: Product 1    1...

  • matlab only Question 4 A restaurant sells five different desserts whose prices are shown below in...

    matlab only Question 4 A restaurant sells five different desserts whose prices are shown below in the following table: Dessert number Unit Price $ 3.98 $ 2.55 $6.90 $9.85 12.50 2 4 Write a Matiab program to display the above menu to the user. The program then prompts the customer for a key board entry of a series of pairs of numbers as follows Dessert Number: Quantity sold The program should then use switch statement to obtain the total price...

  • We use JAVA. Thanks.    Create an application whose main method asks the user to enter...

    We use JAVA. Thanks.    Create an application whose main method asks the user to enter an n by m integer matrix that contains nm integer numbers. n and m should be between 1 and 10. If the user enters a             number less than 1 or greater than 10, the program will continue to ask the user to enter an integer number between 1 and 10. The program should print the sum of the boundary elements of the matrix....

  • (C programing, Not C++) Write a program in C that asks the user to input 10...

    (C programing, Not C++) Write a program in C that asks the user to input 10 numbers. Store these numbers in an array. Then ask the user to input a single number. Your program should execute a linear search on the array, trying to find that number. If the number exists in the array, have the program print out which position/element the number was found at. If the target number is not in the array, have the program print out...

  • programing C,already write part of code (a) Write a function print.array that receives an array of...

    programing C,already write part of code (a) Write a function print.array that receives an array of real numbers and the number of el stored in the array. This function must display the elements of the array in order with each one on a line by itself in a field width of 7 with two decimal places. (See sample output. Recall the format specifier would be "%7.21f"). (b) Sometimes we want to treat an array as a mathematical vector and compute...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • by java langage QI A small online grocery store sells fruits with the following prices: Apple,...

    by java langage QI A small online grocery store sells fruits with the following prices: Apple, 1.500 KWD; Orange, 0.700 KWD; Banana, 1.000 KWD; Peach, 2.500 KWD; and Melon, 1.750 KWD. Write an application that reads a series of pairs of values as follows: 1. fruit name 2. quantity sold Your program should use a switch statement to determine the price for each fruit. It should then calculate and display the total retail value of all sold fruits (e.g., if...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT