This program is supposed to track rainfall statistics, but something is wrong with either the class declaration/implementation. Any help would be greatly appreciated
void Stats::getValues()
{
for (int i = 0; i < numArray; i++)
{
cout << ary[i] << endl;
}
return;
}
double Stats::getTotal()
{
total = 0;
for (int i = 0; i < numArray; i++)
{
total += ary[i];
}
return total;
}
double Stats::getAvg()
{
total = 0;
for (int i = 0; i < numArray; i++)
{
total += ary[i];
}
avg = total / numArray;
return avg;
}
double Stats::getLargest()
{
for (int i = 0; i < numArray; i++)
{
if (largest < ary[i]) {
largest = ary[i];
}
}
return largest;
}
double Stats::getSmallest()
{
for (int i = 0; i < numArray; i++)
{
if (smallest > ary[i]) {
smallest = ary[i];
}
}
return smallest;
}
int main()
{
const int numEl = 12;
double arys[numEl];
Stats rainfall[numEl];
for (int i = 0; i < numEl; i++)
{
cout << "Please enter a rainfall number: ";
cin >> arys[i];
}
for (int i = 0; i < numEl; i++)
{
setValue(i, arys[i]);
}
cout << "The rainfall statistics you entered were: \n";
rainfall.getValues();
cout << "The total rainfall is: ";
rainfall.getTotal();
cout << "\nThe average rainfall is: ";
rainfall.getAvg();
cout << "\nThe largest value is: ";
rainfall.getLargest();
cout << "\nThe smallest value is: ";
rainfall.getSmallest();
@Ericool thank you for the reply, the code compiles and works. Unfortunately I can't use parts of it in my own as I don't understand how it works. For instance, I've never had arguments in my main() parameter list before.
My current problem is that I'm able to read integers into the the class's private data member array via setValue(), but none of my other functions are returning avg, largest, smallest. I just get blank output. Any idea why that might be?
they were returning value but they were not use by the cout instance, the semicolon should tell where an instruction ends. for the main parameters you can ignore them, for now. the rest is up to you to figure it out. good luck :)