Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <array>
- // Jason Sandoz
- void getAvg(double arr[], int SIZE){ // Function to calculate average and total rain fall
- int i = 0;
- double avg, sum = 0;
- for(int i = 0; i < SIZE; i++){
- sum += arr[i];
- }
- avg = (sum / SIZE);
- std::cout << "The Average rainfall is: " << avg << " inches." << std::endl; // Display the average rainfall for the 12 months
- std::cout << "The total rainfall is: " << sum << " inches." << std::endl; // Display the total rainfall for the 12 months
- }
- int main(){
- const int SIZE = 12; // 12 months in a year
- std::array<double, 12> totalRainFall; // create array; the problem is here when I use std::array<double, SIZE> totalRainfall;
- /* When using std::array I get an error that says "initializing argument 1 of double getAvg(double *, int) cannot convert to double */
- for(int i = 0; i < SIZE; i++){ // loop through the array and populate.
- std::cout << "Please input the total rainfall for month: " << i + 1 << " in inches." << std::endl;
- std::cin >> totalRainFall[i];
- if(totalRainFall[i] < 0){ // check for negative input. (evaporation? :D)
- std::cout << "Error: rainfall cannot be negative.\n";
- return 0;
- }
- }
- getAvg(totalRainFall, SIZE); // Call our function to display averages and sums
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement