Arrays Program

Good evening. I am working on a program with two arrays. Both have seven elements. One would be the day of the week, while the other should be the snowfall for that day. Also the program should be able to tell me the Max snowfall in the array, and the average snowfall. I am having trouble getting past the first for loop where the snowfall is entered. If anyone would mind taking a looking and lending a hand, I would greatly appreciate it.

Thank you, my code so far is below.

//This program records average snowfall.


#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
double Date[7];
double Snow_Fall[7];




for (double i = 0; i > 0; i++)
{
cout << "Please enter snowfall." << i + 1 << ":";
cin >> Snow_Fall[0];
cout << endl;
}


system("pause");
return 0;
}
1
2
3
4
5
6
for (double i = 0; i > 0; i++)
{
cout << "Please enter snowfall." << i + 1 << ":";
cin >> Snow_Fall[0];
cout << endl;
}


It should be :
1
2
3
4
5
6
for (int i = 0; i < 7; i++)
{
cout << "Please enter snowfall." << i + 1 << ":";
cin >> Snow_Fall[i];
cout << endl;
}

Elantra:

Thank you, that worked! I appreciated it. How do I code to find the average?

Snow_Fall[0]+[1]+[2].../7? OR something like Snow_Fall[7]/7?
A more elegant way to calculate the average is to iterate over your array, summing all the values. Then divide that sum by the number of values.
closed account (48T7M4Gy)
Use a for loop:

1
2
3
4
5
double total = 0;
for( int i = 0; i < 7; i++)
{
    total += Snow_Fall[i];
... etc
Topic archived. No new replies allowed.