okay if I'm hearing you correctly my code should look something like this:
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
|
#include <iostream> // input output
#include <iomanip> // manipulator
#include <cmath> // math
#include <string> // string
#include <fstream> // file stream
using namespace std;
int main()
{
// declare variables
int outerLoop;
int innerLoop;
int numberOfYears;
double average;
double rainAmount;
ifstream inrain;
ofstream outrain;
inrain.open("inrain.txt"); // open input text
outrain.open("outrain.txt"); // open output text
inrain >> numberOfYears;
for(outerLoop = 1; outerLoop <= numberOfYears; outerLoop++)
{
numberOfYears = 3;
innerLoop = 12;
rainAmount = numberOfYears + innerLoop;
outrain << fixed << endl;
outrain << "Year " << outerLoop << endl;
inrain >> rainAmount;
for(innerLoop = 1; innerLoop <= 12; innerLoop++)
{
inrain >> rainAmount;
outrain << showpoint << setprecision(2) << endl;
outrain << "Inches of rain for month " << innerLoop << " =" << rainAmount << endl;
}
inrain >> rainAmount;
average = rainAmount / 12;
outrain << "The total amount of rainfall in this year was " << average << endl;
}
cout << "To view results, open the outrain.txt file in the same directory" << endl;
cout << "as the source code for this program." << endl;
inrain.close(); // close input text
outrain.close(); // close output text
system("PAUSE");
return 0;
}
|
my output looks like:
Year 1
Inches of rain for month 1 =0.20
Inches of rain for month 2 =0.30
Inches of rain for month 3 =0.40
Inches of rain for month 4 =0.50
Inches of rain for month 5 =0.60
Inches of rain for month 6 =0.70
Inches of rain for month 7 =0.80
Inches of rain for month 8 =0.90
Inches of rain for month 9 =1.00
Inches of rain for month 10 =1.10
Inches of rain for month 11 =1.20
Inches of rain for month 12 =0.00
The total amount of rainfall in this year was 0.08
Year 2
Inches of rain for month 1 =1.20
Inches of rain for month 2 =1.30
Inches of rain for month 3 =1.40
Inches of rain for month 4 =1.50
Inches of rain for month 5 =1.60
Inches of rain for month 6 =1.70
Inches of rain for month 7 =1.80
Inches of rain for month 8 =1.90
Inches of rain for month 9 =12.00
Inches of rain for month 10 =2.00
Inches of rain for month 11 =2.10
Inches of rain for month 12 =2.20
The total amount of rainfall in this year was 0.19
Year 3
Inches of rain for month 1 =2.50
Inches of rain for month 2 =2.60
Inches of rain for month 3 =2.70
Inches of rain for month 4 =2.80
Inches of rain for month 5 =2.90
Inches of rain for month 6 =2.11
Inches of rain for month 7 =2.12
Inches of rain for month 8 =2.12
Inches of rain for month 9 =2.12
Inches of rain for month 10 =2.12
Inches of rain for month 11 =2.12
Inches of rain for month 12 =2.12
The total amount of rainfall in this year was 0.18
but it should look like: (ignoring the alignment).
Data for year 1
Number of inches for month 1: 0.10
Number of inches for month 2: 0.20
Number of inches for month 3: 0.30
Number of inches for month 4: 0.40
Number of inches for month 5: 0.50
Number of inches for month 6: 0.60
Number of inches for month 7: 0.70
Number of inches for month 8: 0.80
Number of inches for month 9: 0.90
Number of inches for month 10: 1.00
Number of inches for month 11: 1.10
Number of inches for month 12: 1.20
Data for year 2
Number of inches for month 1: 0.00
Number of inches for month 2: 1.00
Number of inches for month 3: 1.10
Number of inches for month 4: 1.20
Number of inches for month 5: 1.30
Number of inches for month 6: 1.40
Number of inches for month 7: 1.50
Number of inches for month 8: 1.60
Number of inches for month 9: 1.70
Number of inches for month 10: 1.80
Number of inches for month 11: 1.90
Number of inches for month 12: 12.00
Data for year 3
Number of inches for month 1: 2.00
Number of inches for month 2: 2.10
Number of inches for month 3: 2.20
Number of inches for month 4: 2.30
Number of inches for month 5: 2.40
Number of inches for month 6: 2.50
Number of inches for month 7: 2.60
Number of inches for month 8: 2.70
Number of inches for month 9: 2.80
Number of inches for month 10: 2.90
Number of inches for month 11: 2.11
Number of inches for month 12: 2.12
Over a period of 36 months, 63.03 inches of rain fell.
Average monthly rainfall for the period is 1.75 inches.
if i read in all the months for that year, do i have to give number of months a variable of its own?