Thread: help with proggy!

  1. #1
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    Question help with proggy!

    OK! I shall tell the problem!!! 1. Character constant too long!!!
    2. no match for 'string & == integer'
    3.It pops up and dissapears in Dev C++!!!
    Code:
    #include <iostream.h>
    #include <string>
    
    int main()
    {
    cout << "The world is about to be destroyed. You are in a futuristic spy base." << endl;
    cout << "You will soon go on a mission to save the world. In the corner of the room," << endl;
    cout << "you see a plant. The door is to the north and the basement is down." << endl;
    std::string firstroom;
    cin >> firstroom;
    if(firstroom == 'x plant')
    {
    cout << "As you examine the plant, you spot a glint of silver in the soil." << endl;
    std::string plant;
    cin >> plant;
    if(plant == 'x glint')
    {
    plant:
    cout << "You pick up the glint. It is a keycard to the NETWORK." << endl;
    std::string glint;
    cin >> glint;
    }
    if(plant == 'get glint')
    {
    goto plant;
    }
    return 0;
    }
    Last edited by gcn_zelda; 03-17-2003 at 08:19 PM.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    you need "" around strings and ' ' around single chars. so

    char c = 'c'; // is fine
    string s = ' wassup '; // is an error. need "" not ''
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    goto d;
    *screams* My eyes! My eyes! They're bleeding!

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    Thanks but...

    also, Dev C++ says parse error at end of input

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: Thanks but...

    Originally posted by gcn_zelda
    also, Dev C++ says parse error at end of input
    Every place in your above code where you use single quotes ', replace it with ", as you've already been instructed.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    And if I'm counting correctly, you have more opening braces than closing ones. Looks like you forgot a closing one right after cin>>plant;
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Originally posted by quzah
    *screams* My eyes! My eyes! They're bleeding!

    Quzah.
    I'm so incredibly sick of the constant cracks on the use of goto! Granted it shouldnt be a newbie practice, but goto has its place and its use, and it gets old that people are constantly bashing a perfectly good function. If your going to make a comment like that at least explain it too him, please.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by RoD
    I'm so incredibly sick of the constant cracks on the use of goto! Granted it shouldnt be a newbie practice, but goto has its place and its use, and it gets old that people are constantly bashing a perfectly good function. If your going to make a comment like that at least explain it too him, please.
    At the risk of turning this into an entirely pointless debate on the use of goto, I'll add the following:

    I have yet to ever find a place where it required the use for goto, other than to intentionally obfuscate code. Yes, I've heard it's "handy" for jumping from deep nested loops, but again, I have never ever found use for one.

    Were you to take a few seconds to look at their code, you'd find this is also true here:
    Code:
    int main()
    {
        [--snip text output--]
    
        std::string firstroom;
        cin >> firstroom;
        if(firstroom == 'x plant')
        {
            [--snip text output--]
            std::string plant;
            cin >> plant;
            if(plant == 'x glint')
            {
                plant:
                [--snip text output--]
                std::string glint;
                cin >> glint;
            }
            if(plant == 'get glint')
            {
                goto plant;
            }
            return 0;
    }
    First off, their entire approach to the game is definately wrong. However, allowing for newbie-ism, we can easily fix this to not use goto:
    Code:
    int main()
    {
        [--snip text output--]
    
        std::string firstroom;
        cin >> firstroom;
        if(firstroom == 'x plant')
        {
            [--snip text output--]
            std::string plant;
            cin >> plant;
            if(plant == 'x glint' || plant == 'get glint' )
            {
                [--snip text output--]
                std::string glint;
                cin >> glint;
            }
            return 0;
    }
    I've left their other errors in tact, just for the hell of it. I don't feel the need to bother telling people who won't even read sticky notes on how to use code tags, reasons to or not to use goto.

    Seriously, the person I should be telling is either their instructor, or the author of their book. Goto should be one of the last things taught. Why? Because that's about how useful it is. IE: It's worthless for nearly everything you will ever write in your lifetime. It deserves barely a passing glance, and as such, should be treated and taught in said manner.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ proggy ?
    By MrDrummond in forum C++ Programming
    Replies: 5
    Last Post: 08-03-2004, 12:54 AM
  2. computer problems after proggy installation
    By *ClownPimp* in forum Tech Board
    Replies: 4
    Last Post: 06-03-2003, 05:28 PM
  3. pointer proggy
    By sworc66 in forum C Programming
    Replies: 3
    Last Post: 09-03-2002, 02:41 AM
  4. My best C++ Programs
    By Paro in forum C++ Programming
    Replies: 113
    Last Post: 03-24-2002, 11:52 AM
  5. the history of Wingdings (and other nonsensical things)
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 01-19-2002, 01:51 PM