while function

This is a discussion on while function within the C Programming forums, part of the General Programming Boards category; i am trying to run the following while loop, but no matter what the input is, it keeps giving me ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    124

    while function

    i am trying to run the following while loop, but no matter what the input is, it keeps giving me the answer of "numb is 1".
    what am I doing wrong?

    Code:
    numb=0
    while (year<2009)
    		
    if((year%4==0 && year %100 !=0), year %400==0)	
    {numb=numb+1;
    year=year+1;}
    else 		
    {year=year+1;}
    		
    printf("Numb is %i\n\n",numb);

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Because you're using a comma "," when you mean or "||".

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    While is not a function by the way. I'm not really sure what you would call it, but it definitely is not a function.

    Another note: always keep your code correctly indented. It would have been much easier to read your code if it was organized.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    Quote Originally Posted by goran00 View Post
    i am trying to run the following while loop, but no matter what the input is, it keeps giving me the answer of "numb is 1".
    what am I doing wrong?

    Code:
    numb = 0;
    while (year < 2009)
    {
    	if ( (year &#37; 4 == 0 && year %1 00 != 0) || year % 400 == 0 )
    	{
    		numb++;
    		year++;
    	}
    	else 		
    	{
    		year++;
    	}
    }
    printf("Numb is %i\n\n",numb);
    I believe you are in serious need of learning how to use proper programming style. Please have a read:
    http://cpwiki.sf.net/User:Elysia/Indentation
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21