-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment 5.txt
60 lines (50 loc) · 1.89 KB
/
Assignment 5.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*Student Name: Arno Dunstatter
Course Name: Programming Fundamentals
Course Number: CS1336
Section: 001
Due Date: 3/15/20
Date Completed:3/9/20
Date Submitted:3/9/20 */
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
double sales1, sales2, sales3, sales4, sales5; //declaring sales values for each store
vector<double> sales = { sales1 = 0, sales2 = 0, sales3 = 0, sales4 = 0, sales5 = 0 }; //initializing a vector for easy access to all sales values
ofstream outputFile; //creating our outputFile object
outputFile.open("salesbarchart.txt"); //establishes the "pipeline" to salesbarchart.txt and creates said file
//if it's not already extant
if (outputFile) { //this if statement verifies that the salesbarchart.txt file was opened properly
for (int i = 1; i <= 5; ++i) //will get values for today's sales for each store
{
cout << "Enter today's sales for store " << i << ": ";
do //this will validate the input and repeatedly ask for valid input if the input is invalid
{
cin >> sales[i - 1];
if (sales[i - 1] <= 0) //input validation
cout << "That was not valid. Please enter a positive value for sales: ";
} while (sales[i - 1] <= 0);
}
for (int i = 0; i <= 4; ++i)
{
cout << "Store " << i + 1 << ": "; //output to screen
outputFile << "Store " << i + 1 << ": "; //output to file
for (int j = 0; j <= sales[i] / 100; ++j)
{
if (j > 0)
{
cout << "*"; //output to screen
outputFile << "*"; //output to file
}
}
cout << endl; //new line for each store on the screen
outputFile << endl; //new line for each store in the file
}
outputFile.close(); //closes salesbarchart.txt
}
else //lets the user know that the salesbarchart.txt file wasn't properly opened
cout << "The desired file, salesbarchart.txt, could not open correctly. Please try to run the program again.\n";
return 0;
}