compile error

This is a discussion on compile error within the C++ Programming forums, part of the General Programming Boards category; i am trying to make like a text game based on a choose yur own adventure book and i keep ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    176

    compile error

    i am trying to make like a text game based on a choose yur own adventure book and i keep getting an error that says

    9 C:\Dev-Cpp\madlibgame.cpp
    `c' undeclared (first use this function)

    here is my code



    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(void)
    {
    
        int whattheytype;
        string commands = c;
        int exit;
    
        std::cout<<"ok this is a choose your own adventure game called\n"<<endl;
        std::cout<<"deep space. you will read the page then you will be\n"<<endl;
        std::cout<<"asked to choose which way you want to go and such\n"<<endl;
        std::cout<<"sounds like fun huh? thought so. ok type c to\n"<<endl;
        std::cout<<"get a list of commands. and type exit to leave"<<endl;/* all this is is the introductory for the game*/
        std::cin>>whattheytype;
        if (whattheytype == commands); 
        std::cout<<"eet works!";
        else
        if (whattheytype == 2)
        std::cout<<"yup\n";
    
        std::cout<<"\npress any key and hit enter to quit:";
        std::cin>>exit;
    
           return 0;
    }

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,208
    Change this line:
    Code:
    string commands = c;
    to this:
    Code:
    string commands = "c";

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    now i get


    19 C:\Dev-Cpp\madlibgame.cpp
    no match for `int& == std::string&' operator

    the code is



    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(void)
    {
    
        int whattheytype;
        string commands = "commands";
        int exit;
    
        std::cout<<"ok this is a choose your own adventure game called\n"<<endl;
        std::cout<<"deep space. you will read the page then you will be\n"<<endl;
        std::cout<<"asked to choose which way you want to go and such\n"<<endl;
        std::cout<<"sounds like fun huh? thought so. ok type c to\n"<<endl;
        std::cout<<"get a list of commands. and type exit to leave"<<endl;/* all this is is the introductory for the game*/
        {
        std::cin>>whattheytype;
        if(whattheytype == commands); 
        std::cout<<"eet works!";
        else
        if (whattheytype == 2)
        std::cout<<"yup\n";
    
        std::cout<<"\npress any key and hit enter to quit:";
        std::cin>>exit;
    
           return 0;
    }
    Last edited by sreetvert83; 11-23-2003 at 09:32 AM.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    > int whattheytype;
    > string commands = "commands";
    So make them both int, or make them both string, then you'll be able to compare them

    I'm guessing you'll want to choose
    string whattheytype;

    > int exit;
    exit is also the name of a function in cstdlib
    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.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    ok i have 2 more questions my code as it is now is


    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(void)
    {
    
        string whattheytype;
        string commands = "commands";
        string option1 = "start";
        string leave = "exit";
        std::cout<<"this game was ripped off from the choose your own adventure\n";
        std::cout<<" book called Undergound Kingdom by  Edward Packard\n";
        std::cout<<"ok this is a choose your own adventure game called\n";
        std::cout<<"Underground kingdom. you will read the page then you will be\n";
        std::cout<<"asked to choose which way you want to go and such\n";
        std::cout<<"sounds like fun huh? thought so. ok type commands to\n";
        std::cout<<"get a list of commands. and type exit to leave";/* all this is is the introductory for the game*/
        std::cout<<"\ntype start to start the game!\n"<<endl;
        std::cin>>whattheytype;
        if (whattheytype == commands) 
        std::cout<<"just follow the instructions stupid ass restart the program\n"<<endl;/*insructions*/
        
        else
        if (whattheytype == option1)/*beginning of actual game*/
        std::cout<<"WARNING!!!!!!!!!!!!!\n";
        std::cout<<"\n"<<endl;
        std::cout<<"The Underground Kingdom is not easy to reach. Many Players\n";
        std::cout<<"never get ther. Others never return.\n";
        std::cout<<"    Before starting out on your journey, you may want to read\n";
        std::cout<<"Professor Bruckner's theory, which is set fourth on the next block\n";
        std::cout<<"of text.\n";
        std::cout<<"    Professor Bruckner is a rather boring writer, and i wouldn't\n";
        std::cout<<"suggest that you bother read his theorym exept that, if you ever\n";
        std::cout<<"get to the Underground Kingdom, it might save your life. Good luck!\n";
        
        else /*exiting game*/
        if (whattheytype == leave)
        std::cout<<"press any key to exit\n";
        std::cin>> leave;
        
    
        
    
           return 0;
    }
    now the error i get now is

    37 C:\Dev-Cpp\madlibgame.cpp
    parse error before `else'

    and also i would like to make it so they can type commands and get the command thing then press start and get the game 2 start instead of having to restart teh game each time

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    *points up*

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Use some more braces to group together all the statements you consider to be part of an if statement
    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.

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    ok one more question and then i think i can make the rest of this game the code so far is

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(void)
    {
    
        string whattheytype;
        string commands = "commands";
        string option1 = "start";
        string leave = "exit";
        string theory = "theory";/*variables*/
        string game ="game";
        
        
        std::cout<<"this game was ripped off from the choose your own adventure\n";
        std::cout<<" book called Undergound Kingdom by  Edward Packard\n";
        std::cout<<"ok this is a choose your own adventure game called\n";
        std::cout<<"Underground kingdom. you will read the page then you will be\n";
        std::cout<<"asked to choose which way you want to go and such\n";
        std::cout<<"sounds like fun huh? thought so. ok type commands to\n";
        std::cout<<"get a list of commands. and type exit to leave";/* all this is is the introductory for the game*/
        std::cout<<"\ntype start to start the game!\n"<<endl;
        
        std::cin>>whattheytype;
        if (whattheytype == commands) 
        std::cout<<"just follow the instructions and restart the program\n"<<endl;/*insructions*/
        
        else
        if (whattheytype == option1)/*beginning of actual game*/
        {
        std::cout<<"WARNING!!!!!!!!!!!!!\n";
        std::cout<<"\n"<<endl;
        std::cout<<"The Underground Kingdom is not easy to reach. Many Players\n";
        std::cout<<"never get ther. Others never return.\n";
        std::cout<<"    Before starting out on your journey, you may want to read\n";
        std::cout<<"Professor Bruckner's theory, which is set fourth on the next block\n";
        std::cout<<"of text.\n";
        std::cout<<"    Professor Bruckner is a rather boring writer, and i wouldn't\n";
        std::cout<<"suggest that you bother read his theory exept that, if you ever\n";
        std::cout<<"get to the Underground Kingdom, it might save your life. Good luck!\n"<<endl;
        std::cout<<"type theory to read the theory type game to start the game\n";
        }
            if (whattheytype == theory)
                {
                std::cout<<"bleg";
                }
            else
            if (whattheytype == game)
                {
                std::cout<<"hmm";
                }
        
        else /*exiting game*/
        if (whattheytype == leave)
        {
        std::cout<<"press any key to exit\n";
        std::cin>>leave;
        }
    
        
    
           return 0;
    }

    and it compiles and runs but where it asks you to choose the theory or start the game when you choose either one it ends the program and i want it to execute the game or the theory part any ideas? btw thanks for all the help so far

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    anyone ? i have been trying to fix this problem for about 4 hours now

  10. #10
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    What do you expect? You don't actually have any game code there at the moment. I suggest you create a function to do theory, and a function to start the game. When they specify that they want theory, just call the function, etc etc.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  11. #11
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    i fixed it all by myself hehehehe only took me 6 hours lol anyway all i needed to do was creat string whattheytype2; instead of re using string whattheytype; over and over it compiled and ran fine now i am gonna finish the game anyway here is the code


    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(void)
    {
        string whattheytype;
        string whattheytype2;
        string commands = "commands";
        string option1 = "start";
        string theory = "theory";/*variables*/
        string game ="game";
        string leave = "exit";
        
        
        std::cout<<"this game was ripped off from the choose your own adventure\n";
        std::cout<<" book called Undergound Kingdom by  Edward Packard\n";
        std::cout<<"ok this is a choose your own adventure game called\n";
        std::cout<<"Underground kingdom. you will read the page then you will be\n";
        std::cout<<"asked to choose which way you want to go and such\n";
        std::cout<<"sounds like fun huh? thought so. ok type commands to\n";
        std::cout<<"get a list of commands. and type exit to leave";/* all this is is the introductory for the game*/
        std::cout<<"\ntype start to start the game!\n"<<endl;
        
        std::cin>>whattheytype;
        if (whattheytype == commands) 
        std::cout<<"just follow the instructions and restart the program\n"<<endl;/*insructions*/
        
        
        else
        if (whattheytype == option1)/*beginning of actual game*/
        
        std::cout<<"WARNING!!!!!!!!!!!!!\n";
        std::cout<<"\n"<<endl;
        std::cout<<"The Underground Kingdom is not easy to reach. Many Players\n";
        std::cout<<"never get ther. Others never return.\n";
        std::cout<<"    Before starting out on your journey, you may want to read\n";
        std::cout<<"Professor Bruckner's theory, which is set fourth on the next block\n";
        std::cout<<"of text.\n";
        std::cout<<"    Professor Bruckner is a rather boring writer, and i wouldn't\n";
        std::cout<<"suggest that you bother read his theory exept that, if you ever\n";
        std::cout<<"get to the Underground Kingdom, it might save your life. Good luck!\n"<<endl;
        std::cout<<"type theory to read the theory type game to start the game\n";
        
            std::cin>>whattheytype2;
            if (whattheytype2 == theory)
                
                std::cout<<"bleg";
                
            else
            if (whattheytype2 == game)
                
                std::cout<<"hmm";
                
        else /*exiting game*/
        if (whattheytype == leave)
        
        std::cout<<"press any key to exit\n";
        std::cin>>leave;
        
        std::cout<<"press any key to exit\n";
        std::cin>>leave;
        
        return 0;
    }
    ill post the finish product later thanks for all the help

  12. #12
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    i can get the file to compile but when you try to get the rest of the theory part it flashes it then shuts the prog down anyoen know how i can pause it?

  13. #13
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  14. #14
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    I tried the solution in the faq and it didn't work here is my code can anyone see where i made my mistake?

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(void)
    {
        string whattheytype;
        string whattheytype2;
        string commands = "commands";
        string option1 = "start";
        string theory = "theory";/*variables*/
        string game ="game";
        string leave = "exit";
        int pause;
        int more;
        
        
        std::cout<<"this game was ripped off from the choose your own adventure\n";
        std::cout<<" book called Undergound Kingdom by  Edward Packard\n";
        std::cout<<"ok this is a choose your own adventure game called\n";
        std::cout<<"Underground kingdom. you will read the page then you will be\n";
        std::cout<<"asked to choose which way you want to go and such\n";
        std::cout<<"sounds like fun huh? thought so. ok type commands to\n";
        std::cout<<"get a list of commands. and type exit to leave";/* all this is is the introductory for the game*/
        std::cout<<"\ntype start to start the game!\n"<<endl;
        
        std::cin>>whattheytype;
        if (whattheytype == commands) 
        std::cout<<"just follow the instructions and restart the program\n"<<endl;/*insructions*/
        
        
        else
        if (whattheytype == option1)/*beginning of actual game*/
        
        std::cout<<"WARNING!!!!!!!!!!!!!\n";
        std::cout<<"\n"<<endl;
        std::cout<<"The Underground Kingdom is not easy to reach. Many Players\n";
        std::cout<<"never get ther. Others never return.\n";
        std::cout<<"    Before starting out on your journey, you may want to read\n";
        std::cout<<"Professor Bruckner's theory, which is set fourth on the next block\n";
        std::cout<<"of text.\n";
        std::cout<<"    Professor Bruckner is a rather boring writer, and i wouldn't\n";
        std::cout<<"suggest that you bother read his theory exept that, if you ever\n";
        std::cout<<"get to the Underground Kingdom, it might save your life. Good luck!\n"<<endl;
        std::cout<<"type theory to read the theory type game to start the game\n";
        
            std::cin>>whattheytype2;
            if (whattheytype2 == theory)
                {
                std::cout<<"                         PROFESSOR\n";
                std::cout<<"                         BRUCKNER'S\n";
                std::cout<<"                           THEORY\n";
                std::cout<<"---------------------------------------------------------------\n";
                std::cout<<"The discovery of the Bottomless Crevasse in Greenland by Dr. Nera \n";
                std::cout<<"Vivaldi supports my therory that the earth is not solid, as has\n";
                std::cout<<"been thought, but that it is hollow.  The Bottomless Crevasse is\n";
                std::cout<<"probably the sole route from the earth's surface to a vast Underground\n";
                std::cout<<"Kingdom.  The only other possible link would be an underground river,\n";
                std::cout<<"flowing in alternating directions in response to the tides, but this \n";
                std::cout<<"seems unlikely.\n";
                std::cout<<"How you may ask, was the earth hollowed out?  My studies show that more\n";
                std::cout<<"than a billion years ago a tiny blck hole collided with out planet and\n";
                std::cout<<"lodged in its center, pulling the whole molten core into an incredibly\n";
                std::cout<<"massive sphere only a few hundred meter across.\n";
                std::cout<<"If you were to stand on the inner surface of the earth, like a fly on the\n";
                std::cout<<"shell of an enormous pumpkin, you would see the black hole directly overhead,\n";
                std::cout<<"press any key and hit enter for more of the theory\n";
                std::cin>>more;
                std::cout<<"like a black sun.\n";
                std::cout<<"The Gravity of the earth's thick shell would hold you to the inner shell\n";
                std::cout<<"of the earth, though you would weigh much less than you would on the\n";
                std::cout<<"outer surface because the mass of the Black Sun would tend to pull \n";
                std::cout<<"you toward it. If there were a very tall mountain in the Underground\n";
                std::cout<<"Kingdom and you were to climb to the top of it, you might be pulled\n";
                std::cout<<"up into the Black Sun because gravity gets stronger as you approach\n";
                std::cout<<"a massive object.\n";
                std::cout<<"In all other respects the Black Sun would not be dangerous to any creatures\n";
                std::cout<<"in the Unerground Kingdom.  On the contrary, the Black Sun would be\n";
                std::cout<<"necessary to life in th underworld, but in the opposit way that the sun is\n";
                std::cout<<"necessary to life on the earth's surface.  OUr sun give us heat and keeps us\n";
                std::cout<<"from freezing.  The Black Sun absorbs heat.  If there is an underground \n";
                std::cout<<"kingdom, it is the Blac Sun tha keep its inhabitants from being baked to\n";
                std::cout<<"death by the heat within the earth.\n";
                std::cout<<"type game to start game!\n";
                std::cin>>pause;
                std::cin>>whattheytype2;
                }
            else
            if (whattheytype2 == game)
                {
                std::cout<<"hmm";
                }
            else
            if (whattheytype == leave)
            {
            std::cout<<"press any key to exit\n";
            std::cin>>leave;
        }
    
        return 0;
    }

  15. #15
    Registered User Myownworstenemy's Avatar
    Join Date
    May 2003
    Posts
    8
    im not exactly sure what youre asking, but one major problem is that you have 2 std::cin statements ina row after cout-ing the huge text of the theory... std::cin >> pause; gets user input from standard input and puts it into the variable named "pause"... it doesnt actually pause the screen. If you want a way to pause the screen, try system("PAUSE");

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 06:17 PM
  4. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM

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