grr not working no matter what i do

This is a discussion on grr not working no matter what i do within the C++ Programming forums, part of the General Programming Boards category; why will my code not work ive declared everything Code: #include <cstdlib> #include <iostream> #include <string> using namespace std; void ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    grr not working no matter what i do

    why will my code not work ive declared everything
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    
    using namespace std;
    void create();
    void createdata(string race);
    int yn;
    int main()
    {
    string select;
    do
    {
        cout<<"welcome to my little game i like to call\n";
        cout<<"FABLE RIPOFF\n";
        cout<<"\n\n\n";
        cout<<"please choose an option,\n";
        cout<<"tutorial is recommended for beginners\n\n";
        cout<<"play game(type play)\n";
        cout<<"load(type load)\n";
        cout<<"tutporial(type tut)\n";
        cout<<"quit(type quit)\n";
        cin>>select;
        cout<<endl;
        if(select == "play" || select == "Play")
        {
                  system("cls");
                  create();
                  cin.get();
        }
        if(select == "tut" || select == "Tut")
        {
                  cout<<"under construction\n";
                  cin.get();
        }
        if(select == "quit" || select == "Quit")
        {
                  break;
        }
        cin.get();
    }while(select != "quit" || select != "Quit");
    }
    void create(){
    string race;
    string yn;
    cout<<"which race do you want to be?\n";
    cout<<"\n\n";
    cout<<"human(press h)\n";
    cout<<"elf(press e)\n";
    cout<<"mage(press m)\n";
    cout<<"demon(press d)\n";
    cout<<"please choose an option\n";
    cin>>race;
    if(race == "h" || race == "H" )
    {
    cout<<"humans are not a preferred race for battles mainly because of there\n";
    cout<<"stupidity,they are however the only race that shops will talk to\n";
    cout<<"but because of this they cant go into other lands shops other than\n";
    cout<<"philostone.at the moment no human has survived even a minimal attack\n";
    cout<<"from another monster,will you?\n";
    cout<<"are you sure you want to be human\n";
    cin>>yn;
    if(yn == "y" || yn == "Y")
    {
    ERROR HERE:createdata(string race);
    }
    else
    {
        system("cls");
             create();
    };
    }
    else if(race == "e" ||race == "E")
    {
    cout<<"elves are an amazing race,known for there absoloute mastery in \n";
    cout<<"archery,choosing this race will assure you a spot in the archers\n";
    cout<<"guild,they are also the only race other than mages to be\n";
    cout<<"able to do magic,but dont let that fool you there no mages\n";
    cout<<"but there very small which means this is what they have to rely\n";
    cout<<"on just magic and archery but being small gives them amazing speed\n";
    cout<<"allowing them to flee from every battle they face\n";
    cout<<"are you sure you want to be an elf?\n";
    cin>>yn;
    if(yn == "y" || yn == "Y")
    {
    cout<<"under construction\n";
    cin.get();
    }
    else
    {
        system("cls");
             create();
    };
    }
    else if(race == "m" || race == "M")
    {
    cout<<"mages are the most powerfull magicians and also most likely\n";
    cout<<"to finish the game to the very end,and being able to join\n";
    cout<<"the magic guild gives them the arsenal of magic they need\n";
    cout<<"provided they have the money to buy the spells of coarse\n";
    cout<<"are you sure you want to be a mage?\n";
    cin>>yn;
    if(yn == "y" || yn == "Y")
    {
    cout<<"under construction\n";
    cin.get();
    }
    else
    {
        system("cls");
             create();
    };
    }
    else if(race == "d" || race == "D")
    {
    cout<<"demons dont care about archery or magicks they care about\n";
    cout<<"BRUTE strenth there dumb as a doorknob but stronger than \n";
    cout<<"anything else in the world\n";
    cout<<"nobody whose fought a demon in a brute strenth battle\n";
    cout<<"has lived to tell the tale\n";
    cout<<"are you sure you want to be a demon?\n";
    cin>>yn;
    if(yn == "y" || yn == "Y")
    {
    cout<<"under construction\n";
    cin.get();
    }
    else
    {
        system("cls");
             create();
    };
    };
    }
    void createdata(string race){
         ERROR HERE:string race;
         if(race == "h" || race =="H")
         string huname;
         cout<<"what is your humans name?\n";
         ERROR HERE:cin>>huname;
         cout<<"hmm"<< huname <<"if your sure\n";
         cout<<"here are your stats\n";
         }
    }
    };
    Last edited by lilhawk2892; 07-05-2006 at 09:10 PM.

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    what do you mean "won't work"? fails to compile? crashes? doesn't do what you want? tries to send porn to your boss?

    post some info if you expect help (hint: compiler, os, error message, location of crash, etc)
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338
    Is there a compiler error? What is it? What line?

    Be careful when calling a function that you remove the argument type if you copy and paste. Watch out for missing braces.
    Last edited by Daved; 07-05-2006 at 09:10 PM.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    oh sorry i was in a hurry
    Compiler: Default compiler
    Building Makefile: "C:\Dev-Cpp\Makefile.win"
    Executing make...
    make.exe -f "C:\Dev-Cpp\Makefile.win" all
    g++.exe -c trpg.cpp -o trpg.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

    trpg.cpp: In function `void create()':
    trpg.cpp:65: error: expected primary-expression before "race"

    trpg.cpp: In function `void createdata(std::string)':
    trpg.cpp:136: error: declaration of 'std::string race' shadows a parameter
    trpg.cpp:140: error: `huname' undeclared (first use this function)
    trpg.cpp:140: error: (Each undeclared identifier is reported only once for each function it appears in.)

    trpg.cpp: At global scope:
    trpg.cpp:144: error: expected declaration before '}' token

    make.exe: *** [trpg.o] Error 1

    Execution terminated

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    I also put where the errors are in the code provided

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338
    >> trpg.cpp:136: error: declaration of 'std::string race' shadows a parameter
    That one should be pretty self explanatory. Do you understand what it is saying? The others might be fixed by the hints in my previous post/edit.

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    thanks i finally figured it out and the huname should get fixed pretty easily

    huname fixed!!!!!!!!!!
    thanks everyone
    Last edited by lilhawk2892; 07-05-2006 at 09:24 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 07:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 07:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM

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