0

so I am making a program to make a console ran text video game, like Zork. And I wanted to make it open end for the question like you can type "Walk Away" and it will understand. Here is my program:

#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>

wchar_t Choice;

using namespace std;

int main()
{
    int Choice;
    {
        printf("Welcome to Text Adventure Game!\n\n");
        printf("To play just read the text and enter in the numberic value (i.e. 1, 2, or 3)\nto make a decision. Your decesions will be reflected as you continue on in the game.\n\n\n");
        printf("Creators: Dillon Dugan and Justin Doubt.\n\n\n");
        printf("If there is a problem with your game, please contact us on twitter @DillonMDugan or through e-mail at dillonmdugan@yahoo.com.\n\n\n");
        printf("Enjoy.\n\n\n");
        system("PAUSE");
        printf(" \n\n\n\n\n");
        printf("You come out of darkness.\nConfused and tired, you walk to an abandoned house.\nYou walk to the door.\n");
        printf("What do you do?\n1. Walk Away.\n2. Jump.\n3. Open Door.\n\n");
        string Choice;
        cin>>Choice;
        cin.ignore();
        printf("\n\n\n");

        switch(Choice)
        {
            case 'Walk_Away':
            {
                //Walks Away
                printf("The House seems too important to ignore.\n");
                printf("What do you do?\n1. Jump.\n2. Open Door.\n\n");
                printf(" \n\n\n");
            }
        }
    }
}

And I am getting an error saying that on line 29, "Error: switch quantity not an integer

Can you help me fix this? And if I am doing anything wrong (besides using printf) please tell me

  • 1
    You can't switch on strings, consider using an enum and mapping the strings to it. – Retired Ninja Dec 17 '13 at 03:10
  • Use an `if` ... `else if` chain. – Pete Becker Dec 17 '13 at 03:22
  • 1
    Since you also asked about what else you might be doing wrong, declaring 3 different type `Choice` variables all visible at the same place is generally a bad idea, and `'whatever'` is not a literal string, use quotes as you have elsewhere. – Retired Ninja Dec 17 '13 at 03:25

0 Answers0