|
-
Dec 19th, 2000, 12:04 AM
#1
Thread Starter
Addicted Member
Code:
#include <stdio.h>
int main() {
int temper[7];
int day, sum;
printf("Enter in 7 temps:\n ");
for (day=0;day<7;++day){
printf("Enter in temperature for day %d: ", day);
scanf("%d",&temper[day]);
}
sum=0;
for(day=0;day<7;++day)
sum += temper[day];
printf("Average is %d.",sum/7);
}
Okay first off,
1. in the for loop it initializes day to 0.
Day is not an array so how does it hold all seven integers?
2.in the second for loop it sets the variable day back to zero. How does it remember the temps then?
3. the sum+= temper[day]. What exactly is this function saying +=?
Thanks in advance.

-
Dec 19th, 2000, 12:56 AM
#2
Day isnt the array, temper is the array, day is just a counter.
-
Dec 19th, 2000, 12:43 PM
#3
Frenzied Member
Question 1:
for (day=0;day<7;++day)
day = 0; Well thats a no brainer
day < 7; Loop while day is less than 7
++day; Each loop, add one to day. You could write it like day = day + 1;
Question 2:
scanf("%d",&temper[day]); You are putting the value that the user inputs in to the temper array at position day. So it would be like &temper[1] = userinput; &temper[2] = userinput; This will continue till day is more than 7.
Question 3:
sum+= temper[day]; You could write this like sum = sum + temper[day]; What you are doing is adding the value in the temper array at position day to sum. += is just a shortcut to saying sum = sum + temper[day];
Hope that answers it for you
[Edited by Technocrat on 12-19-2000 at 12:46 PM]
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|