@
Venged
You won't understand everything right away. I just gave you a template kind of thing. Copy it to some cpp file on your PC, then edit it and put your stuff in it and see what you can make it do.
Compile it and execute it and see what happens. Then edit it, change a thing or two, and repeat.
For example, you could replace the comment "do something with 'number' here" with the code
cout << number;
. Compile and run.
I've edited my last post to add a few more comments so you can get a better idea of what is going on.
Now, to calculate an average of some collection of numbers, you need only two things: the sum of the numbers, and the number of numbers. Now think about how you can use a loop:
If I ask, what is 2 + 3 you say 5.
If I ask, what is 2 + 3 + 7 you say 12.
If I ask, what is 2 + 3 + 7 + 1 you say 13.
If I ask, what is 2 + 3 + 7 + 1 + 8 you say 21.
Now I ask, what is the average?
Hope this helps.
@
hartmannr76
I see you've been ruined by MS... ;->
This site has excellent tutorials:
http://www.cplusplus.com/doc/tutorial/pointers.html
That's another good way to keep information. The only condition is that you must know beforehand how many items you plan to store. (The strength of the STL is that array containers can resize themselves dynamically as needed.)
BTW. Your
days array is completely unnecessary, since the day is always
i+1
. Hence to find a day all you have to do is check:
1 2 3 4 5 6 7 8
|
if ((1 > searchDay) or (searchDay >= numDays))
{
cout << "\nYou did not provide information for that day.\n";
}
else
{
cout << "\nYour inputed temperature was " << temps[ searchDay -1 ] << " degrees.\n";
}
|
Anyway, nice idea!