Thread: Little help - If statements

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    1

    Little help - If statements

    hi guys, I am a bit of a novice, and am having trouble getting this program to compile.

    Please could anyone help me...

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    void main()
    {
      int number;
      int guess;
    
      srand ( time(NULL) );
    
      number = rand() % 1000 + 1;
    
      do {
        printf ("I'm thinking of a number, between 1 and 1000.\n Try to guess it... \n");
        scanf ("%d",&guess);
    
        if (number < guess) 
    	{
    		printf ("The secret number is lower...\n");
    	}
    	else 
    		if (number > guess) 
    		{
    			printf ("The secret number is higher...\n");
    		}
    		else
    			if (number != guess)
    			{
    				printf ( "Congratulations, you guessed it!\n");
    			}
      }
      system ("PAUSE");
      exit(0);
    }
    It just gives on error when I compile it;

    Error C2061 : Syntax error : identifier 'system'

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    It looks like you attempted to create a do...while loop. You added the "do" part, but forgot the "while". It should be in the form of:
    Code:
    do
    {
        // code here
    } while(condition);
    bit∙hub [bit-huhb] n. A source and destination for information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Skipping If Statements?
    By CBecker5000 in forum C Programming
    Replies: 1
    Last Post: 11-08-2009, 04:05 PM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  4. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  5. Need help with "if" statements
    By Harryt123 in forum C Programming
    Replies: 22
    Last Post: 05-14-2006, 08:18 AM