#include "stdafx.h"
#include <string>;
#include <iostream>;
#define newline '\n';
using namespace std;
string initial;
string a;
string b;
string c;
string object;
string sword;
string testswing;
int main()
{
cout << "you awake in a forest with no memory what do you do?";
cout << newline;
cin >> initial;
if (initial == "look left" || initial == "look forward" || initial == "look behind"){
cout << newline;
cout << "you see a dense forest";
cout << newline;
}
else (initial == "look right"); {
cout << newline;
cout << "you see a opening with a shape in the distance";
cout << newline;
}
cin >> a;
cout << newline;
if (a == "go right")
{
cout << newline;
cout << "you see a trap lucily you dident set it off. might want to SEARCH AREA before going into open areas";
cout << newline;
cin >> c;
cout << newline;
if (c == "go forward")
{
cout << newline;
cout << "you arrive at the strange object do you want to INSPECT OBJECT?";
cout << newline;
if (object == "inspect object")
{
cout << newline;
cout << "You see the object is a sword stuck in a stone";
cout << newline;
cin >> sword;
if (sword == "pull sword");
{
cout << newline;
cout << "the sword breaks free of the stone you have obtained the SHORT SWORD";
cout << newline;
cout << "use this item when appropriate by using the command SWING SWORD";
if (testswing == "swing sword");
{
cout << newline;
cout << "you swing the sword it hits the rock and breaks";
cout << newline;
cout << "we told you only to use the sword when appropriate now look what you've done your adventure is over already";
cout << newline;
system("pause");
return 0;
}
}
}
else
{
cout << newline;
cout << "the object draws you twards it seemingly by magic";
cout << newline;
}
}
else (c == "go left" || c == "go right"|| c == "go back");
{
cout << "there is nothing but empty feilds for miles you get lost and die";
cout << newline;
system("pause");
return 0;
}
}
else {
cout << "you cant go that way";
}
}
程序在第一個用戶輸入後退出,不管輸入是什麼,如果它的外觀離開,向前看,後面看,或看起來正確程序退出後,我無法找到問題。它說用代碼0(0X0)退出程序我找不到第一個用戶輸入後程序退出的原因
當你使用調試器,通過這個代碼一行在一個時間步驟,你做了什麼意見,就其執行流程? –
'else(initial ==「look right」);'這在語法上是正確的,在語義上是無意義的! '否則,如果(初始==「看起來正確」)'可能是你在做什麼。之後你也會有類似的錯誤。 –
解決這些問題的正確工具是您的調試器。在*堆棧溢出問題之前,您應該逐行執行您的代碼。如需更多幫助,請閱讀[如何調試小程序(由Eric Lippert撰寫)](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。至少,您應該\編輯您的問題,以包含一個[最小,完整和可驗證](http://stackoverflow.com/help/mcve)示例,該示例再現了您的問題,以及您在調試器。 –