Thread: Newbie Compiling Problem

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    2

    Newbie Compiling Problem

    I don't have much experience programming in C++ so I was using the quiz part of this site to practice a bit. One of the quizzes was to complete a Guessing Game program. I did but I'm having a very hard time compiling it. I'm sure it's a simple thing but hopefully, someone here can point me to my errors. Below is my code and below that, I'll show how I'm compiling and the results I get.

    Thanks in advance.

    Code:
    #include <stdlib.h>
    #inlcude <iostream>
    
    using namespace std;
    
    int main()
    {
            int number=rand()%10+1;
            int guess = -1;
            int trycount = 0;
    
            while(guess != number && trycount < 8)
            {
                    cout<<"Please enter a guess: ";
                    cin>>guess;
    
                    if(guess < number)
                            cout << "Too low" <<endl;
    
                    if(guess > number)
                            cout<<"Too high" <<endl;
    
                    trycount++;
    
            }
    
            if(guess == number)
                    cout << "BINGO!!! You guessed the number!";
    
            else
                    cout << "Sorry, the number was: " << number;
    
            return 0;
    
    }
    g++ guessingGame.cpp -o guessingGame
    guessingGame.cpp:2:2: error: invalid preprocessing directive #inlcude
    guessingGame.cpp: In function ‘int main()’:
    guessingGame.cpp:14: error: ‘cout’ was not declared in this scope
    guessingGame.cpp:15: error: ‘cin’ was not declared in this scope
    guessingGame.cpp:18: error: ‘endl’ was not declared in this scope
    guessingGame.cpp:21: error: ‘endl’ was not declared in this scope
    guessingGame.cpp:28: error: ‘cout’ was not declared in this scope
    guessingGame.cpp:31: error: ‘cout’ was not declared in this scope

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You have a typo error on the second line. "#inlcude" should be "#include".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    2
    Ugh, thank you. I swear I looked at that several times.

    Thanks again.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > guessingGame.cpp:2:2: error: invalid preprocessing directive #inlcude
    Always read the first error message.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Compiling
    By Flakster in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 01:09 AM
  2. Newbie question: Problem with malloc
    By Ikim in forum C Programming
    Replies: 2
    Last Post: 02-05-2006, 10:11 PM
  3. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  4. newbie Windows problem...
    By gcn_zelda in forum Windows Programming
    Replies: 9
    Last Post: 06-07-2003, 02:14 PM
  5. newbie coding problem
    By rippascal in forum C++ Programming
    Replies: 10
    Last Post: 01-08-2002, 11:45 PM