I'm new to this and feel totally lost. The problem is to read info from a text file into a program that will calculate total sales and average daily sales for three people. The output is then written to another file. I have written several versions of loop codes, but none will run, and I keep getting an error in Visual Studio that the debug file cannot be found. Any help would be greatly appreciated!
The text file looks like this:
Mickey 400
Daisy 300
Donald 500
Mickey 1000
Daisy 700
Donald 200
// this program uses a loop to read in values
//from a file
// I am modifying to read two values from each line of input
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
/*int a, b; (this is the inspiration for the structure)
while (infile >> a >> b)
{
// process pair (a,b)
}*/
int main()
{
ifstream inputFile; // file stream object
inputFile.open("Sales.txt");// open the input file
string a;
int b,
count;
double average;
while (inputFile >> a >> b){
if (a= "Mickey"; b+=){
count+=;
average =( b/count);}
if (a= "Daisy"; b+=){
count+=;
average = (b/count);}
if (a= "Donald"; b+=){
count+=;
average = (b/count);}
}
}
//close the file
inputFile.close();
ofstream outputFile;
//open the output file
outputFile.open("Totals.txt");
outputFile << "Mickey's Total Sales: "; << mickeyTotalSales << ". Mickey's Daily Average: "; << (mickeyAverage);
outputFile << "Daisy's Total Sales: " << daisyTotalSales << ". Daisy's Daily Average: " << (daisyAverage);
outputFile << "Donald's Total Sales: " << donaldTotalSales << ". Donald's Daily Average: " << (donaldAverage);
system("pause");
return 0;
}