Newbie Compiling Problem

This is a discussion on Newbie Compiling Problem within the C++ Programming forums, part of the General Programming Boards category; I don't have much experience programming in C++ so I was using the quiz part of this site to practice ...

  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
    21,593
    You have a typo error on the second line. "#inlcude" should be "#include".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 09:11 PM
  3. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 11:53 AM
  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, 10:45 PM

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