Karim runs 10 spaza shops in different suburbs, each named Skuld Huiswinkel. He asks all the storekeepers to record the final day total sales so that he can determine which of his shops has more sales for each day. He has approached you to write a program that will store the name of the location for each shop and the total sales for the day.
3.1 The program should capture the Skuld Huiswinkel name and the corresponding total sales value amount for the day, all in one cin line.
3.2 The program should store the spaza name and the total sales value in two parallel arrays.
(8 Marks)
3.3 The program should keep a running total that will give the total sales from all spaza shops and also show the average sales for the day.
3.4 Before the program closes, it should store all the values of the parallel arrays in a text file named SHW_Sales.txt. Each line in the file must have the shop location name and the sales value, with these 2 items separated by a space
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(){
string names[10];
int sales[10];
fstream file("sales.txt", ios::out);
cout<<"Enter the details\n";
for(int i=0; i<10; i++){
cout<<"Enter the Skuld Huiswinkel name and final day sales for day "<<(i+1)<<"\n";
string n;
cin>>names[i]>>sales[i];
}
int sum = 0;
for(int i=0; i<10; i++){
cout<<names[i]<<" "<<sales[i]<<endl;
file<<names[i]<<" "<<sales[i]<<endl;
sum += sales[i];
}
cout<<"The average sales is: "<<sum/10<<endl;
}
Comments
Leave a comment