In: Computer Science
Outside of main declare two constant variables: an integer for number of days in the week and a double for the revenue per pizza (which is $8.50). Create the function prototypes.
Create main
Inside main:
Submit the .cpp file and a screen shot in Canvas
Screen Shots:
please write the code for c++
CODE SCREENSHOTS:
OUTPUT SCREENSHOT:
CODE:
#include <bits/stdc++.h>
using namespace std;
const int days = 7; // days in the week
const double revenue = 8.50; // revenue per pizza
bool check(int temp) // checks if the entered value is positive
{
return (temp >= 0); // returns true for positive
}
void display(int a[]) // for the report display
{
cout << endl
<< endl
<< "PIZZA REPORT\n\n";
for (int i = 0; i < days; i++)
{
cout << "Day " << i + 1 << ": " << a[i] << " pizza(s) sold\n"; // pizzas sold each day
}
}
int calcSum(int a[]) // calculate total sum
{
int sum = 0;
for (int i = 0; i < days; i++)
sum += a[i];
return sum;
}
int calcAvg(int a[]) // calculate avg pizzas sold in a day
{
int sum = calcSum(a);
return sum / days; // returns int cause pizza is a whole
}
double calcTotalRevenue(int a[]) // calculate total revenue
{
double sum = 0;
for (int i = 0; i < days; i++)
sum += a[i] * revenue;
return sum;
}
double calcAvgRevenue(int a[]) // calculate avg revenue in a day
{
double sum = calcTotalRevenue(a);
return sum / days;
}
int main()
{
int a[days];
int sum; // total sum of pizzas sold in a week
int avg; // average pizzas sold per day
int temp;
double totalRevenue; // The total revenue from the pizza sold for the week
double avgRevenue; // The average revenue per day
cout << "\nEnter the values: \n";
// Input values
for (int i = 0; i < days; i++)
{
cout << "Day " << i + 1 << ": ";
cin >> temp;
if (!check(temp))
{
cout << "Enter a positive value\n";
cout << "Day " << i + 1 << ": ";
cin >> temp;
}
a[i] = temp;
}
display(a);
sum = calcSum(a);
avg = calcAvg(a);
totalRevenue = calcTotalRevenue(a);
avgRevenue = calcAvgRevenue(a);
cout << "\nThe total number of pizzas sold for the week: " << sum;
cout << "\nThe average number of pizzas sold per day: " << avg;
cout << "\nThe total revenue from the pizza sold for the week: " << totalRevenue;
cout << "\nThe average revenue per day: " << avgRevenue;
cout << "\n\nTHANK YOU";
return 0;
}
Please comment in case of doubts or queries.
Kindly upvote :)