#include <iostream>
using namespace std;
void get_temps(int choice)
{
if(choice == 1)
{
double temps[12];
for(int i = 0; i < 12; i++)
{
int month_num= i+1;
cout << &"Please enter the average temperature for month " [month_num];
cin >> temps[i];
}
}
if(choice == 2)
{
double temps[10];
for(int i = 0; i < 10; i++)
{
int year_num = i+1;
cout <<"Please enter the average yearly temperature for year " [ year_num];
cin >> temps[i];
}
}
}
double get_vector_average(double temps[], int size)
{
double total = 0;
for(int i = 0; i < size; i++)
{
total = total + temps[i];
}
double average = total/size;
return average;
}
int main ()
{
int choice;
do{
cout << "Please enter:\n\t1 to calculate the average yearly temperature\n\t2 to calculate the average temperature for a decade\n\t3 to quit\nEnter number now: ";
cin >> choice;
if (choice < 1 || choice > 3)
{
cout <<"Input Error!\n\n";
}
}while(choice < 1 || choice > 3);
if(choice == 1)
{
get_temps(1);
cout << "The average temperature for the year is " + get_vector_average(double temps[12], 12);
}
if(choice == 2)
{
get_temps(2);
cout << "The average temperature for the decade is " + get_vector_average(double temps[10], 10);
}
if(choice == 3)
{
cout << "Goodbye...";
}
return 0;
}
This is my code and I cannot get it to run. My code consists of two user defined functions: The first is used to get the temperatures and store them in a vector. If the user picks yearly temp average, it stores 12 temps. If the user picks decade average temp, the vector will store 10 temps. The second is used to find the average of the temperatures. Both will be called in the main function corresponding to what the user chooses. My code will not compile. It says the array needs an initializer. I am not sure how to do this. Any help would be appreciated.