B (C++) [27] You are requested by a SuperStore (Spar) in Soshanguve to calculate it’s earning for the week (the store opens the entire week) and determine the day with the highest and lowest earnings. The Store comprises of two sections namely the Food section and the Liquor store. Your C++ program should prompt the total sales for each section for each day and store the total sales for the day into an array. At the end of the week It should display a report for Management for the total sales for that week, the day the lowest sales and the day with the highest sales were recorded. Refer to below screen shot for sample Input and Output.
#include <iostream>
using namespace std;
int main()
{
int n=7;
int food[n];
int liquor[n];
cout<<"\nEnter total sales for food store: "<<endl;
for(int i=0;i<n;i++){
cout<<"\nEnter total sales for day "<<i+1<<": ";
cin>>food[i];
}
cout<<"\nEnter total sales for liquor store: "<<endl;
for(int i=0;i<n;i++){
cout<<"\nEnter total sales for day "<<i+1<<": ";
cin>>liquor[i];
}
int sum1=0,sum2=0;
for(int i=0;i<n;i++){
sum1+=food[i];
sum2+=liquor[i];
}
int total=sum1+sum2;
cout<<"\nTotal sales for this week is: "<<total<<endl;
int maxf=food[0],maxl=liquor[0];
int minf=food[0],minl=liquor[0];
int ma1=0,ma2=0;
for(int i=0;i<n;i++){
if (food[i]>=maxf){
maxf=food[i];
ma1=i;
}
if (liquor[i]>=maxl){
maxl=liquor[i];
ma2=i;
}
}
int mn1=0,mn2=0;
for(int i=0;i<n;i++){
if (food[i]<=maxf){
maxf=food[i];
mn1=i;
}
if (liquor[i]<=maxl){
maxl=liquor[i];
mn2=i;
}
}
int ma,mn;
if(maxf>maxl)
ma=ma1;
else
ma=ma2;
if(minf>minl)
mn=mn1;
else
mn=mn2;
cout<<"\nThe day with the highest sales is day "<<ma+1;
cout<<"\nThe day with the lowest sales is day "<<mn+1;
return 0;
}
Comments
Leave a comment