Thread: I have done it again

  1. #1
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179

    I have done it again

    Ok I am once again doing another small and useless test so please don't ask me why I have printed what I have I just did so..

    Code:
    #include <stdio.h>
    
    int userNum;
    int x=1;
    
    int main(void)
    {
    	printf("Please enter the number 1: ");
    	scanf("%d", &userNum);
    
    	{
    	if(userNum != x)
    	
    		printf("Hey! I told you to type the number 1 not %d\n\n", userNum);
    
    		else
    			printf("Thank you for followind my instructions\n\n");
    	}
    	
    	do
    {
    	printf("This is the do part");
    } while(userNum>1; x--); /*this is it*/
    
    	do 
    {
        printf("ndlfasdf");
    } while ( x > 0 );
    	
    
    
    	return 0;
    }
    The do while statement that has the comment [this is it] beside it, I don't know why it won't work, the one under it is from my compilers index I was comparing them so what is wrong with mine, I know it looks wrong but my compiler just says I have 2 errors, I need to put some brackets in but they only make more problems.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Like this:
    Code:
    #include <stdio.h>
    
    int userNum;
    int x=1;
    
    int main(void)
    {
       printf("Please enter the number 1: ");
       scanf("%d", &userNum);
    
       if(userNum != x)
          printf("Hey! I told you to type the number 1 not %d\n\n",  userNum);
       else
          printf("Thank you for followind my instructions\n\n");
    	
       do
       {
          printf("This is the do part");
          x--;
       } while(userNum>1); /*this is it*/
    
       do 
       {
          printf("ndlfasdf");
       } while ( x > 0 );
    	
       return 0;
    }
    You had mismatching braces and your
    while(userNum>1; x--);
    is invalid syntax.

  3. #3
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Ok thank you, I wasn't sure of how to set up the do while corretly, thanks.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

Popular pages Recent additions subscribe to a feed