Code is completely finished, but I forgot one part. The program will read in a year, the number of times it needs to run (runs), and then several sets of inches. It works perfectly for one set of data, I'm not sure how to make it continue going. It needs to work with up to 3 sets. Included are two given sets of data.
Edit: I'm now realizing how gross this code actually is. Trying to fix it, but I feel like I just took 10 steps backwards.
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
int year;
int runs;
int inches = 0;
double avg;
int total = 0;
int month = 1;
int count = 01;
ifstream infile;
ofstream outfile;
outfile.open("out.txt");
infile.open("text.txt");
infile >> year >> runs;
while (count <= runs)
{
while (month <= 12)
{
outfile << "** " << year << " **";
infile >> inches;
total = total + inches;
outfile << "\nJanuary " << setw(6) << inches << " inches";
infile >> inches;
total = total + inches;
outfile << "\nFebruary " << setw(5) << inches << " inches";
infile >> inches;
total = total + inches;
outfile << "\nMarch " << setw(8) << inches << " inches";
infile >> inches;
total = total + inches;
outfile << "\nApril " << setw(8) << inches << " inches";
infile >> inches;
total = total + inches;
outfile << "\nMay " << setw(10) << inches << " inches";
infile >> inches;
total = total + inches;
outfile << "\nJune " << setw(9) << inches << " inches";
infile >> inches;
total = total + inches;
outfile << "\nJuly " << setw(9) << inches << " inches";
infile >> inches;
total = total + inches;
outfile << "\nAugust " << setw(7) << inches << " inches";
infile >> inches;
total = total + inches;
outfile << "\nSeptember " << setw(4) << inches << " inches";
infile >> inches;
total = total + inches;
outfile << "\nOctober " << setw(6) << inches << " inches";
infile >> inches;
total = total + inches;
outfile << "\nNovember " << setw(5) << inches << " inches";
infile >> inches;
outfile << "\nDecember " << setw(5) << inches << " inches";
avg = total / 12.00;
outfile << "\nTotal " << setw(11) << fixed << setprecision(2) << avg
<< " inches";
outfile << "\n\n\n";
year++;
total = 0;
break;
}
count++;
}
outfile.close();
infile.close();
return 0;
}
|
1990 5
10 12 14 15 12 9 4 4 8 12 9 10
12 10 5 10 12 5 14 4 6 11 6 11
13 5 2 13 19 11 11 3 9 12 1 12
20 6 12 9 8 8 8 10 9 13 9 4
11 3 9 12 1 12 20 6 12 9 8 8
1910 11
10 8 3 10 12 14 15 12 9 4 4 8
12 9 10 12 10 5 10 12 5 14 4 6
11 6 11 4 2 17 9 9 9 0 0 8
13 5 2 13 19 11 11 3 9 12 1 7
12 20 6 12 9 8 8 8 9 13 9 4
11 3 9 12 1 12 20 6 12 9 8 8
3 5 2 13 19 11 11 3 9 12 1 12
6 2 3 8 9 10 11 0 9 2 5 11
2 6 12 9 8 8 8 1 9 13 9 4
11 3 9 12 1 12 20 10 12 4 5 2
19 0 2 18 3 7 9 2 0 6 5 12