Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ code help

Name: Colossal McFaggot 2008-02-26 5:02

I heard /prog/ was a terrible place to come for advice on account of "everyone there is a fucking asshole," but I come with an open mind hoping at least one person will help me. 

I just started programming, I have had zero prior experience and have only read a few chapters into the book I'm using (C++ for dummies: complete desk reference)

So I made this VERY primitive text game, I don't know how to use classes and objects yet, so I'm pretty much just using a function within the main to handle commands, which is sloppy, but I honestly don't know jack shit yet. 

#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
string command(string input)
{
       string crntlocation;
       string output;
       string n1 = "You are in a dark room";
       crntlocation = n1;
       string error = "Huh?";
       if (input == "look") {
                output = crntlocation;
                return output;
       }
       else {
            output = error;
       }    
}
               
int main(int argc, char *argv[])
{
    string output;
    string playername;
    string deathmsg;
    string promptinput;
    string promptoutput;
    bool alive = true;
    cout << "What is your name?" << endl;
    cin >> playername;
    cout << "Hello, " << playername << "!" << endl; 
    while (alive == true){
          cin >> promptinput;
          promptoutput = command(promptinput);
          cout << promptoutput << endl;
    }
    cout << deathmsg << endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}



The problem: When I put in multiple words when prompted by CIN, the words following the first will spill over to the next available CIN line.

How do I get it so that everything typed in prompted by a single CIN line is treated as a whole input, and not multiple inputs broken by spaces?  This would help me out a lot, and I promise I'll stop being a faggot and continue reading before I start asking questions.

Name: Anonymous 2008-02-26 13:16

What's the syntax for random numbers in Haskell?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List