-4

My cin >> OneDecision; keeps being skipped, and then it kind of just ends the whole program there.

I tried cin.getline(OneDecision, 40), but no matter what. It won't work, and I don't know why not. And I can't really continue on with the game unless I fix it.

This is for a class assignment, it's going to a be a short text-based horror game. If I could get some help, that'd be nice. I'm an amateur, have mercy.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <iomanip>
#include <limits>


using namespace std;

int main()
{
    char player1 [40],
    char fear [40];
    char friend1 [40];
    char friend2 [40];
    int start;
    char option [40], option2 [40], option3 [40], option4 [40];
    char OneDecision [40], OneDecision2 [40];

    cout << "Hey.... what's your name?\n";
    cin.get(player1, 40);
    cout<< "Well, " << player1 << ". What is your biggest fear?\n";
    cin >> fear ;
    cout <<"Name one friend.\n";
    cin >> friend1;
    cout << "Name another friend... or make one up if you have none.\n";
    cin >> friend2;
    cout<< "Are you ready to play?\n 1. Yes or 2. No.\n";
    cin >> start ;

    if (start == 1)
       {
       cout << "You'll later regret it...\n You have entered HORROR HOUSE.";
       }

    else if (start == 2)
       {
        cout << "I don't blame you. Why the hell would you want to enter a    horror house to be honest...\n\n\n\n";
        cout << "                                      END GAME.";
       }


     Sleep(2500);
     system("cls");


     cout<< "You, " << friend1 << " and " << friend2 << " are staying at the mansion " << friend1 << "'s family recently \nbought.";
     cout << "It's night, and you are in your room sleeping.\nWhen you here a loud noise, a thump.\nYou get out of bed, and look around to see if something fell.\n";
     cout << "The door you though you closed was left open, and but other than that nothing is wrong.\n\n\n\n\n";

     Sleep (12000);

     cout << "               But then you hear a horrible scream from outside.\n\n";
     cout << "                Run to window and see? Or Run to " << friend1 << "'s room?\n";
     cin.get(option, 40);
     cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // The program terminates at this line, I've tried other ways of saying for it to ignore the next line but none of them worked, this was the last thing I tried. 


     if (string(option) == "run to window" || string(option) == "window")
     {
       cout << "      \n  You run to the window and see " << friend1 << " laying dead on the ground outside.\n";
       cout << "               Go downstairs and out the house toward" << friend1 << "?\n                Or run to " << friend2 << "'s room to wake them up." ;
       cin.get(OneDecision, 40); 

     if (OneDecision == "go downstairs")
     {
      cout << "You are running downstairs. You run out of the house, and    search you're backyard for" << friend1 << ", but , you can't find their body.";

     }

     return 0;
T Chanel
  • 1
  • 2
  • 2
    If any of your inputs have spaces then you need to use `getline` on any of those inputs. – NathanOliver May 24 '16 at 15:02
  • 1
    And here is the answer for your next problem, which will arise after you will start using 'getline': http://stackoverflow.com/a/21567292/3410396 – Revolver_Ocelot May 24 '16 at 15:24
  • 1
    `option == "run to window"` only works if `option` is a `std::string`. With a C style char array you need to use `strcmp`. – Bo Persson May 24 '16 at 15:28
  • 1
    Also `if x = a or b` works in Cobol, but in C and C++ you have to write `if (x == a || x == b)` – Bo Persson May 24 '16 at 15:30
  • @Revolver_Ocelot . Thank you for that article, I took heed to your advice, but I am still encountering some problems, as in my program still terminates, do you have any more advice or suggestions? – T Chanel May 26 '16 at 14:57

1 Answers1

2

Answer

You need to change:

if (option == "run to window" || "window")

to:

if (string(option) == "run to window" || string(option) == "window")
JFed-9
  • 247
  • 2
  • 16
JFed8
  • 108
  • 9