So I have trouble calling data from main function (an array with variables you input) and wasn't sure how to pass it to a float getTotal function. Here is my code:
#include <iostream> #include <iomanip> using namespace std; float getTotal(float [], int ) { double total = 0; for (int i=1; i<ARRAYSIZE; i++) { total += inputs[i]; } cout << "The total rainfall for the year is " << total << "inches." << endl; return total; } float getAverage(float [], int) { //code goes here } int main() { const int ARRAYSIZE = 13; int inputs[ARRAYSIZE], i=1; do { cout << "Enter the rainfall (in inches) for month #" << i << ": "; cin >> inputs[i]; if ( inputs[i] < 0 ) { cout << "Please enter a non-negative number for rainfall in month " << i << " :"; cin >> inputs[i]; } i++; } while (i < 13); float getTotal(float inputs[], int ARRAYSIZE); float getAverage(float inputs[], int ARRAYSIZE); }
So I want to call the array data from main and calculate the total in the getTotal section. I've tried various ways, none of which worked.