Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Directions: Complete the following homework assignment using the description giv

ID: 3851305 • Letter: D

Question

Directions:

Complete the following homework assignment using the description given in each section.   

Purpose:

Use a sentinel loop to gather an indefinite number of inputs

Use loops to check to make sure user input is valid

Use a switch statement and menu to handle different types of inputs

Use of loops and conditionals to control the flow of the program

Submission information:

Submit this assignment by the deadline – NO LATER! It must be submitted before the date. Not doing so WILL result in a zero, no exceptions. If you have problems with this contact Jacob (the TA). DO NOT WAIT TILL THE LAST DAY TO EMAIL HIM. Do not submit on blackboard or by email!

submit CS1050 HW1 homework1.c

Description:

We will be creating a program to generate a simple report from information about the number of sales of various items in a movie theatre. This movie theatre sells movie tickets, which cost them nothing, as well as popcorn, candy, and soda, which do. We must collect information from the user about which kind of sale, how many sales of that kind, how much they sold the item for, and, in some cases, how much the item was from their wholesaler.

As we do not know how many or what kind of items they wish to process, we must present the user with a menu giving them the options of which type of sale they wish to process or to exit and show the report. As the users may not be experienced using computer systems, we should make sure they enter valid data (valid menu selections, no negative number of sales, no negative money values, etc.). The user will NOT attempt to enter values of the wrong type, such as a string when expecting an integer. When the program encounters invalid data, it must only reprompt for that single piece of data; the program must not restart the entry process.

For this program, we are interested in three pieces of information regarding these transactions. The first piece of information is the revenue, or how much money did they get from the customers. The second piece of information is what expenses the theatre had, or how much money did it cost them for the items they sold. For the purposes of this assignment, we will ignore other costs such as personnel. Finally, the third piece of information is what profits were made on the sales that they had, or how much money from the revenue is left after the expenses.

In this program, we only need to compute the total revenue, expenses, and profits after all the inputs and place them into a report after the user chooses to exit and show the report. Make sure that your program output follows the example below. Remember that bolded items are input from the user!

Example:

$ gcccompile homework1.c -g
$ ./a.out

Please enter which type of transaction you wish to record:

     1. Movie Ticket Sales

     2. Popcorn Sales

     3. Soda Sales

     4. Candy Sales

     5. Show report and exit

Selection: 1

Please enter the number of sales: 123

Please enter the sale price of one item: 11.50

Please enter which type of transaction you wish to record:

     1. Movie Ticket Sales

     2. Popcorn Sales

     3. Soda Sales

     4. Candy Sales

     5. Show report and exit

Selection: 2

Please enter the number of sales: 37

Please enter the sale price of one item: 2.75

Please enter the wholesale costprice of one item: 1.17

Please enter which type of transaction you wish to record:

     1. Movie Ticket Sales

     2. Popcorn Sales

     3. Soda Sales

     4. Candy Sales

     5. Show report and exit

Selection: 3

Please enter the number of sales: -3

Invalid number of sales, please try again: 83

Please enter the sale price of one item: 1.78

Please enter the wholesale costprice of one item: 0.57

Please enter which type of transaction you wish to record:

     1. Movie Ticket Sales

     2. Popcorn Sales

     3. Soda Sales

     4. Candy Sales

     5. Show report and exit

Selection: 7

Invalid Selection, please try again: 4

Please enter the number of sales: 27

Please enter the sale price of one item: 1.17

Please enter the wholesale costprice of one item: 0.39

Please enter which type of transaction you wish to record:

     1. Movie Ticket Sales

     2. Popcorn Sales

     3. Soda Sales

     4. Candy Sales

     5. Show report and exit

Selection: 4

Please enter the number of sales: 58

Please enter the sale price of one item: 2.28

Please enter the wholesale price of one item: 0.97

Please enter which type of transaction you wish to record:

     1. Movie Ticket Sales

     2. Popcorn Sales

     3. Soda Sales

     4. Candy Sales

     5. Show report and exit

Selection: 5

------------Report------------

Total Revenue          1827.82

Total Expenses          157.39

------------------------------

Total Profits         1670.43

Explanation / Answer

The answer is as follows:

#include<stdio.h>

void main(){

int choice;
int num_sales;
float unit_price;
float wholesale_price;
float total_revenue;
float total_expenses;
int invalid = 0;

total_revenue = 0;
total_expenses = 0;
do {
        printf("Please enter which type of transaction you wish to record ");

        printf("1.Movie Ticket Sales ");
        printf("2.Popcorn Sales ");
        printf("3.Soda Sales ");
        printf("4.Candy Sales ");
        printf("5.Show report and exit ");

        printf("Selection:");
        scanf("%d", &choice)
        switch(choice) {
             case 1:
                     invalid = 0;
                     do {
                        if (invalid == 0)
                            printf("Please enter number of sales:");
                        else
                           printf("Invalid number of sales,please try again:");
                        scanf("%d", &num_sales);
                        if (num_sales < 0)
                           invalid = 1;
                        else
                           invalid = 0;
                     } while (num_sales < 0)

                     do {
                        if (invalid == 0)
                            printf("Please enter the sale price of one item:");
                        else
                           printf("Invalid sale price of one item,please try again:");
                        scanf("%d", &unit_price);
                        if (unit_price < 0)
                           invalid = 1;
                        else
                           invalid = 0;
                     } while (unit_price < 0)
                     total_revenue = total_revenue + num_sales * unit_price;

             case 2:
                     invalid = 0;
                     do {
                        if (invalid == 0)
                            printf("Please enter number of sales:");
                        else
                           printf("Invalid number of sales,please try again:");
                        scanf("%d", &num_sales);
                        if (num_sales < 0)
                           invalid = 1;
                        else
                           invalid = 0;
                     } while (num_sales < 0)

                     do {
                        if (invalid == 0)
                            printf("Please enter the sale price of one item:");
                        else
                           printf("Invalid sale price of one item,please try again:");
                        scanf("%d", &unit_price);
                        if (unit_price < 0)
                           invalid = 1;
                        else
                           invalid = 0;
                     } while (unit_price < 0)

                     do {
                        if (invalid == 0)
                            printf("Please enter the wholesale costprice of one item:");
                        else
                           printf("Invalid wholesale cost price of one item,please try again:");
                        scanf("%d", &wholesale_price);
                        if (wholesale_price < 0)
                           invalid = 1;
                        else
                           invalid = 0;
                     } while (wholesale_price < 0)

                     total_revenue = total_revenue + num_sales * unit_price;
                     total_expenses = total_expenses + num_sales * wholesale_price;

             case 3:
                     invalid = 0;
                     do {
                        if (invalid == 0)
                            printf("Please enter number of sales:");
                        else
                           printf("Invalid number of sales,please try again:");
                        scanf("%d", &num_sales);
                        if (num_sales < 0)
                           invalid = 1;
                        else
                           invalid = 0;
                     } while (num_sales < 0)

                     do {
                        if (invalid == 0)
                            printf("Please enter the sale price of one item:");
                        else
                           printf("Invalid sale price of one item,please try again:");
                        scanf("%d", &unit_price);
                        if (unit_price < 0)
                           invalid = 1;
                        else
                           invalid = 0;
                     } while (unit_price < 0)

                     do {
                        if (invalid == 0)
                            printf("Please enter the wholesale costprice of one item:");
                        else
                           printf("Invalid wholesale cost price of one item,please try again:");
                        scanf("%d", &wholesale_price);
                        if (wholesale_price < 0)
                           invalid = 1;
                        else
                           invalid = 0;
                     } while (wholesale_price < 0)

                     total_revenue = total_revenue + num_sales * unit_price;
                     total_expenses = total_expenses + num_sales * wholesale_price;


             case 4:
                     invalid = 0;
                     do {
                        if (invalid == 0)
                            printf("Please enter number of sales:");
                        else
                           printf("Invalid number of sales,please try again:");
                        scanf("%d", &num_sales);
                        if (num_sales < 0)
                           invalid = 1;
                        else
                           invalid = 0;
                     } while (num_sales < 0)

                     do {
                        if (invalid == 0)
                            printf("Please enter the sale price of one item:");
                        else
                           printf("Invalid sale price of one item:,please try again:");
                        scanf("%d", &unit_price);
                        if (unit_price < 0)
                           invalid = 1;
                        else
                           invalid = 0;
                     } while (unit_price < 0)

                     do {
                        if (invalid == 0)
                            printf("Please enter the wholesale costprice of one item:");
                        else
                           printf("Invalid wholesale cost price of one item,please try again:");
                        scanf("%d", &wholesale_price);
                        if (wholesale_price < 0)
                           invalid = 1;
                        else
                           invalid = 0;
                     } while (wholesale_price < 0)

                     total_revenue = total_revenue + num_sales * unit_price;
                     total_expenses = total_expenses + num_sales * wholesale_price;


             case 5: printf("-------------Report----------- ");
                     printf("Total Revenue :%f", total_revenue);      
                     printf("Total Revenue :%f", total_expenses);
                     printf("------------------------------------ ");
                     printf("Total Profits : %f", total_revenue - total_expenses);

        }
} while (choice != 5)
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote