so ive been working on this code that will ask the user to input the amount of rainfall for each month and at the end it will display the total amount of rain for the year and the month that had the most and the least amount of rain also display the amount of rain that fell those months
Im having trouble displaying the stats. Right now i just have the total being displayed but its some weird number.
Anybody have some suggestion would be appreciated and yes using a class is required.
i have it in three files and header file and two source files.
header file
#include <iostream>
#include "stdafx.h"
#include "rain.h"
usingnamespace std;
int main()
{
double rain[12]; //puts users inputs into the array
string months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
double monthDay[12]; //increment month number in the loop
int monthNum = 0;
// user inputs the rainfall amount for each month
for (int i = 0; i < 12; i++)
{
cout << "Enter the rainfall (in inches) for month " << months[i] << ": ";
cin >> rain[i];
monthDay[i] = monthNum; //array increments in the loop and saves a new number for the monthNum
}
Rainfall raindata(rain, monthNum); //saves info to the rainfall class
//display total rainfall and the driest month and wettest month and the amount of rain that fall those months
cout << "-------------------------------------------------" << endl;
cout << "Total rainfall: " << raindata.getTotal() << " inches." << endl;
system("pause");
return 0;
#include <iostream>
#include "rain.h"
using std::cin;
using std::cout;
using std::endl;
Rain::Rain(double rainfall_per_month[]) :
rainfall{rainfall_per_month}
{}
void Rain::calculateTotal()
{
//getting the total rainfall count for the year
for (int count = 0; count < 12; count++)
total += rainfall[count];
}
void rain::calculateWettestDriest()
{
driest_month_number = 0;
// We need a high number, otherwise it will always
// be less than fallen rainfall
driest_month_rainfall = 999999999;
wettest_month_number = 0;
wettest_month_rainfall = 0;
//find the lowest and highest number in the array
for (int i = 0; i < 12; i++)
{
if (rainfall[i] < driest_month_rainfall) {
driest_month_rainfall = rainfall[i];
driest_month_number = i;
}
if (rainfall[i] > wettest_month_rainfall) {
wettest_month_rainfall = rainfall[i];
wettest_month_number = i;
}
// And what if two months have the same amount of rainfall? ;-)
}
}