View Single Post
Old Mar 16th, 2008, 3:31 PM   #1
commodore
Programmer
 
Join Date: Nov 2005
Location: Estonia
Posts: 97
Rep Power: 0 commodore is an unknown quantity at this point
Newb interactive fiction

I'm trying to learn C++ and I started coding an interactive fiction game for practice and I can't get this to compile:
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
 
void handle_input(std::string input)
{
    if (input=="quit")
    {
        std::cout<<"Goodbye";
        std::exit(0);
    }
 
    else if (input=="look"){std::cout<<currentRoom.description;}
 
    else {std::cout<<"I don't understand what you're saying\n";}
}
 
class Room
{
    public:
        std::string description;
        std::vector<Room> exits;
};
 
int main()
{
    Room firstRoom;
    firstRoom.description="Description of first room";
    Room currentRoom=firstRoom;
 
    std::cout<<"Hi"<<"\n";
    std::string input;
 
    while (true)
    {
        std::cout<<">>> ";
        std::cin>>input;
        handle_input(input);
    }
    return 0;
}
What am I doing wrong and what am I doing bad?
commodore is offline   Reply With Quote