Thread: Help for a newbie?

  1. #1
    Registered User
    Join Date
    Oct 2012

    Question Help for a newbie?

    Hi guys.
    I am new to C++ programming, and i would like a bit of help. My compiler is saying that "m" is 'not declared in this scope'in this code:

     #include <iostream>#include <math.h>
    using namespace std;
    int main() {
    cout<<"you stand in a clearing in the forest, North of you is a house with an open letterbox in front of it and a locked gate beside said letterbox.  To the South and West are a mass of brambles.  To the East is a path through the trees.\n";
    char a;
      if (a==m);{
       cout<< "yes";}

    Where have i gone wrong?
    Last edited by cowleyj; 10-03-2012 at 01:44 PM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Line 9 does a test "a==m" (I'm using double quotes simply to contain text). There is no variable named m anywhere, hence the compiler's complaint. If you want to compare a with the character 'm', the test needed is "a == 'm'" (note the single quotes around the m).

    Also note that, on line 9, you have a misplaced semi-colon. Because of that, even if you get the code to compile, the string "yes" will always be written to cout, regardless of results of the test.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Thank you very much. It is fixed now.

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    You seriously need to learn how to format your code properly: IP Banned - GIDNetwork
    Also, there should be no semicolon after the if statement.
    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. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  2. Newbie needs help..
    By xpress urself in forum C++ Programming
    Replies: 3
    Last Post: 07-26-2007, 07:22 PM
  3. newbie help
    By winnerpl in forum C Programming
    Replies: 5
    Last Post: 10-10-2004, 07:37 AM
  4. C++ newbie / linux not so newbie question
    By goldmonkey in forum C++ Programming
    Replies: 7
    Last Post: 12-13-2003, 12:27 PM
  5. help please (newbie with C)
    By Yaj in forum C Programming
    Replies: 4
    Last Post: 06-01-2002, 06:02 PM