Basic C++ Help for n00b.

This is a discussion on Basic C++ Help for n00b. within the C++ Programming forums, part of the General Programming Boards category; Okay, I just just started learning C++, and was trying to use what I know to make a very primitive ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    2

    Basic C++ Help for n00b.

    Okay, I just just started learning C++, and was trying to use what I know to make a very primitive and cheesy RPG-ish thing. My code came up with a lot of errors when I tried to use the Borland compiler, though. I've tried to fix it, but can't figure out how.
    The errors I've got now are a bunch of these ones:
    "undefined symbol '____' in function main(),"
    and "Statement missing ; in function main()"

    On line 25 I also got "Possibly incorrect assignment in funtion main ()"

    Hopefully you can see what I'm trying to do. So what am I doing wrong?


    Code:
    #include <iostream>
    #include <string>
    
    int main()
    {
     int attack=5;
     string namey;
     int move;
     int bughp=17;
    
     cout<<"Welcome Adventurer to This fabulous RPG."<<endl;
     cout<<"What would your name be?"<<endl;
     cin>>namey;
     cout<<"Hello" <<namey <<"How are you today?"<<endl;
     cout<<"Oh no!  A ladybug has landed on your head, violating your personal space, and therefore challenging you to a fight."endl;
     while(bughp>0)
     {
      cout<<"How will you torture.. er... teach a lesson to this miniscule insect... er... perilous beast? 1. Kick it, or 2. punch it? Make your choice, and insert the number "endl;
      cin>>move;
      if(move==1)
      {
       bughp=bughp-attack/2;
       cout<< "you deal a rather puny kick to the ladybug"
       }
      else if(move=2)
      {
       bughp=bughp-attack;
       cout<< "you give the bug a small bop on the head"
       }
      else
      {
       cout<<"you decide to try something screwy.   Unfortunately, it doesn't work, and you spontaneously explode"<<endl;
       }
      }
     cout<< "you defeated the ladybug."
     }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > cout<<"Oh no! A ladybug has landed on your head, violating your personal space, and therefore challenging you to a fight."endl;

    You forgot the << before endl.
    cout<<"Oh no! A ladybug has landed on your head, violating your personal space, and therefore challenging you to a fight." << endl;

    > cout<<"How will you torture.. er... teach a lesson to this miniscule insect... er... perilous beast? 1. Kick it, or 2. punch it? Make your choice, and insert the number "endl;
    Same problem here.

    cout<<"How will you torture.. er... teach a lesson to this miniscule insect... er... perilous beast? 1. Kick it, or 2. punch it? Make your choice, and insert the number " << endl;

    > cout<< "you deal a rather puny kick to the ladybug"
    Missing semicolon here.
    cout<< "you deal a rather puny kick to the ladybug";

    > else if(move=2)
    You need double equals for equality.
    else if(move==2)

    > cout<< "you give the bug a small bop on the head"
    Missing semicolon here.
    cout<< "you give the bug a small bop on the head";

    > cout<< "you defeated the ladybug."
    Missing semicolon here.
    cout<< "you defeated the ladybug.";

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,751
    Folding long strings would be a good idea
    Code:
    cout << "Oh no!  A ladybug has landed on your head"
            ", violating your personal space, "
            "and therefore challenging you to a fight." << endl;
    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.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    2
    ok. I'll try to avoid screen stretching in the future.
    I guess I did miss a bunch of semi-colons and <<'s. That fixes some of the problems, but it still says

    ERROR E2451 rpg.cpp 7: Undefined symbol 'string' in function main ()
    ERROR E2379 rpg.cpp 7: Statement missing ; in function main ()
    ERROR E2451 rpg.cpp 11: Undefined symbol 'cout' in function main ()
    ERROR E2451 rpg.cpp 11: Undefined symbol 'endl' in function main ()
    ERROR E2451 rpg.cpp 13: Undefined symbol 'cin' in function main ()
    ERROR E2451 rpg.cpp 13: Undefined symbol 'namey' in function main ()

    I'm not seeing where the other semi-colon goes, and I don't know what they mean by undefined.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,751
    #include <iostream>
    #include <string>

    These are new C++ headers

    Follow them with this line
    using namespace std;


    Or change all your use of these objects into say
    std::cout << "hello world" << std::endl;
    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.

  6. #6
    Banned borko_b's Avatar
    Join Date
    Jun 2002
    Location
    Well... I live in Bulgaria :)
    Posts
    100
    You forgot to "use" the standart namespace ...

    Code:
      //...
      #include<string>
      using namespace std;
      //...
    ( or you must change string to std::string )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 05:28 AM
  3. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 08:41 PM
  4. Basic Calc
    By Universe in forum C++ Programming
    Replies: 12
    Last Post: 07-17-2002, 11:07 PM

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