Results 1 to 3 of 3

Thread: Help w. terms

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    143
    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.


  2. #2
    Guest
    Day isnt the array, temper is the array, day is just a counter.

  3. #3
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    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
  •  



Click Here to Expand Forum to Full Width