The programs description: Write a program that reads a data file named sales.dat. The program should then display a bar graph comparing each store’s sales and also output the sales bar graph to a file names results.dat. Create each bar in the bar graph by displaying a row of asterisks. Each asterisk should represent $100 of sales.
It's using 2 resource files in visual studio, sales.txt and results.txt. So basically, I had the program working, and I submitted it for my assignment. I re-opened it today to mess with it, and it's completely stopped working. It appears to not be reading from sales.txt. sales.txt just has random integers in it on each line. example, 1000, 1200, 1400. The output would show 10, 12 and 14 asterisks on each line in results.txt and in the console.
the issue is that it says store 1: store 2: and so forth, but shows no asterisks.
int main() {
int storeAmount = 0;
double sales = 0.0;
int starAmount = sales / 100; //gets the amount of stars needed
ifstream inFile("sales.txt"); //opens the file sales.txt which is a resource file
ofstream outFile("results.txt"); //opens the file results.txt which is our output file
string outputStars = ""; //holds the stars for the bar graph
cout << "Please input the amount of stores:" << endl; //input the amount of stores
cin >> storeAmount;
cout << "SALES BAR CHART:" << endl; //header output
cout << "Each * = $100" << endl;
for (int storeNum = 0; storeNum < storeAmount; storeNum++) { //loops to the max store amount
inFile >> sales; //variable sales holds the value of each of the lines in sales.txt
for (int i = 0; i < starAmount; i++) { //adds stars onto the string
outputStars += "*";
}
cout << "Store " << storeNum + 1 << ": " << outputStars << endl; //ouputs in the console
outFile << "Store " << storeNum + 1 << ": " << outputStars << endl; //outputs to the file
if (inFile.eof()) { //stops the duplication of the last line if the store amount is greater than the numbers in sales.txt
break;
}
}
outFile.close(); //closes the files
inFile.close();
system("pause");
return 0;
}