Hello Evelynmkm27,
Going over your revision it looks like you are going backwards.
Your struct:
1 2 3 4 5 6 7 8 9 10
|
struct WeatherStatistics
{
const int NUM_YEAR = (2017, 2018, 2019, 2020);
double First_Quarter_Rain_Amount;
double Second_Quarter_Rain_Amount;
double Third_Quarter_Rain_Amount;
double Fourth_Quarter_Rain_Amount;
double Total_Annual_Rain_Amount;
double Average_Quarterly_Rain_Amount;
};
|
Line 3 is not required and the way you have written it will only store "2020" in the variable. The way that you initialized the variable one might think that you are trying to initialize an array that is not defined as an array. The comma here does not do anything that you may be thinking except to store the last number in the variable. After that I do not understand how you intend to use this.
The rest of the lines are the variables required for the "struct".
Your 1st prototype is good although I did add a 2nd parameter in my version.
Your next 4 prototypes look like they will be the same function with only a slight difference inside the function.
In "main" the 1st line of code duplicates what you defined in the "struct". This may not be a problem of defining a variable with the same name, but you may have a problem later on. One of the definitions may never be used.
The next part you do not have is an actual object of the "struct" defined in "main" to use. Because you have a "struct" for each of 4 different years an array of "structs" seems the most logical choice here.
When I wrote the code for the "getYearData" function the function does 1 thing only. Well 1 thing in 2 parts. First a while loop get the input from the keyboard and then checks if the input is in the proper range. When you get that far I will go over it with you.
Next I used a switch to determine which variable in the struct needs the input. This way the nested for loop in "main", (hint, hint, nudge, nudge), that calls this function only has to deal with 1 piece of data at a time. A better choice would be to create an array in the struct with a size of 4, 1 element for each quarter, but this does not go along with the directions.
In your second code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
cout << "Enter first quarter rain amount ";
cout << ":";
cout << "Enter second quarter rain amount";
cout << ": ";
cout << " Enter third quarter rain amount";
cout << ": ";
cout << "Enter fourth quarter rain amount";
cout << ": ";
cin >> Total_Annual_Rain_Amount_Year;
|
You have 8 lines of code that prompt for input, but you never enter anything. The "cin" statement is asking for the user to do the math when the directions call for a function to do this calculation. It does not make any sense and you never store the input into the "struct", so what do you expect the "struct to do?
Your 2 "cout" statements can be combined into just 1 "cout" as:
cout << "Enter first quarter rain amount: ";
. You do not need a separate "cout" just for the (:) and if you notice after the (:) here there is a space and no (\n) or "endl". This put the "cin" on the same line as the prompt and looks much nicer on the screen.
With what I have done so far my input looks like this:
Enter the following information:
Enter data for year 1:
Enter rain fall for quarter 1: 1.1
Enter rain fall for quarter 2: 2.2
Enter rain fall for quarter 3: 3.3
Enter rain fall for quarter 4: 4.4
Enter data for year 2:
Enter rain fall for quarter 1:
|
If you want to get fancy you could define an array of "std::string"s and have the prompt say something like:
Enter rain fall for 1st quarter:
or even spell out "1st" if you want. Not necessary, but a thought.
At the end of "main" under the comment "calculate total and average" everything is wrong. First off all that meaningless code should be 2 function calls. And what is there does not work.
Andy