Write a program that lets the user enter the total rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts.
I am fairly sure I do not have it entirely correct based on reading through my book, but I cant pinpoint exactly what I am doing wrong, which is probably pretty obvious. I am getting quite a few different errors, but for the most part they are
I have quite a few invalid type errors, as well as invalid conversion, and too many arguements and the like. Here is my code.
// Chapter 7, Programming Challenge 2
// RainFall Statistics
#include<iostream>
#include <iomanip>
using namespace std;
// Constant for the number of months
const int NUM_MONTHS = 12;
// Function prototypes
double getTotal(double [], int);
double getAverage(double [], int);
double getLargest(double [], int, int &);
double getSmallest(double [], int, int &);
double getTotal(int rainFall,double NUM_MONTHS[])
{
double total = 0;
for (int count = 0; count < NUM_MONTH; count++)
total += NUM_MONTH[count];
return total;
}
double getAverage(int rainFall,double NUM_MONTH[])
{getTotal(rainFall,NUM_MONTH)
average= total/NUM_MONTHS;
return average;
}
double getHighest(int rainFall, double NUM_MONTHS[]) //I left out the subScript peice as I was not sure how to procede with that;
{
double largest;
largest = NUM_MONTHS[0];
for ( int month = 1; month <= NUM_MONTHS; month++ ){
if ( values[month] > largest ){
largest = values[month];
return largest;
}
double getSmallest(int rainFall, double NUM_MONTHS[])
{
double smallest;
smallest = NUM_MONTHS[0];
for ( int month = 1; month <= NUM_MONTHS; month){
if ( values[month] < smallest ){
smallest = values[month];
return smallest;
}
int main()
{
// Array to hold the rainfall data
double rainFall[NUM_MONTHS];
// Get the rainfall for each month.
for (int month = 0; month < NUM_MONTHS; month++)
{
// Get this month's rainfall.
cout << "Enter the rainfall (in inches) for month #";
cout << (month + 1) << ": ";
cin >> rainFall[month];
// Validate the value entered.
while (rainFall[month] < 0)
{
cout << "Rainfall must be 0 or more.\n"
<< "Please re-enter: ";
cin >> rainFall[month];
}
}
// Set the numeric output formatting.
cout << fixed << showpoint << setprecision(2) << endl;
// Display the total rainfall.
cout << "The total rainfall for the year is ";
cout << getTotal(rainFall, NUM_MONTHS)
<< " inches." << endl;
// Display the average rainfall.
cout << "The average rainfall for the year is ";
cout << getAverage(rainFall, NUM_MONTHS)
<< " inches." << endl;
// Now display the largest & smallest amounts.
// The subscript variable will be passed by reference
// the the getLargest and getSmallets functions.
int subScript;
// Display the largest amount of rainfall.
cout << "The largest amount of rainfall was ";
cout << getLargest(rainFall, NUM_MONTHS, subScript)
<< " inches in month ";
cout << (subScript + 1) << "." << endl;
// Display the smallest amount of rainfall.
cout << "The smallest amount of rainfall was ";
cout << getSmallest(rainFall, NUM_MONTHS, subScript)
<< " inches in month ";
cout << (subScript + 1) << "." << endl << endl;
return 0;
}
I really want to understand exactly what I am doing wrong, so I thank you for your help in advance.
This post has been edited by gamebrain89: 26 November 2008 - 09:30 PM

New Topic/Question
Reply




MultiQuote




|