Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么代码不断跳转以返回main();? 嘿,我是C++新手,我正在练习“做你自己的冒险游戏”。 我不知道问题是什么,我相信这与我的char变量有关,主要是我将发布main.cpp的代码。尽管有其他外部头文件,但我看不到发布它们的理由。我的代码将在运行时不会给我一个错误,如果我的if-else语句被破坏/my-char,我看不出它如何做到这一点变数_C++_If Statement_Char_Adventure - Fatal编程技术网

为什么代码不断跳转以返回main();? 嘿,我是C++新手,我正在练习“做你自己的冒险游戏”。 我不知道问题是什么,我相信这与我的char变量有关,主要是我将发布main.cpp的代码。尽管有其他外部头文件,但我看不到发布它们的理由。我的代码将在运行时不会给我一个错误,如果我的if-else语句被破坏/my-char,我看不出它如何做到这一点变数

为什么代码不断跳转以返回main();? 嘿,我是C++新手,我正在练习“做你自己的冒险游戏”。 我不知道问题是什么,我相信这与我的char变量有关,主要是我将发布main.cpp的代码。尽管有其他外部头文件,但我看不到发布它们的理由。我的代码将在运行时不会给我一个错误,如果我的if-else语句被破坏/my-char,我看不出它如何做到这一点变数,c++,if-statement,char,adventure,C++,If Statement,Char,Adventure,谢谢你的帮助 #include <iostream> //LVL1 #include "C:\Users\QuestionMark\Desktop\Make Your Own Adventure\LVL1\Dog.h" #include "C:\Users\QuestionMark\Desktop\Make Your Own Adventure\LVL1\Dream.h" #include "C:\Users\QuestionMark\Desktop\Make Your Own Ad

谢谢你的帮助

#include <iostream>
//LVL1
#include "C:\Users\QuestionMark\Desktop\Make Your Own Adventure\LVL1\Dog.h"
#include "C:\Users\QuestionMark\Desktop\Make Your Own Adventure\LVL1\Dream.h"
#include "C:\Users\QuestionMark\Desktop\Make Your Own Adventure\LVL1\GTFO.h"

using namespace std;

int main(){

    cout << "Welcome to my 'MAKE YOUR OWN ADVENTURE GAME!!!'\n";
    cout << "Have Fun and enjoy the ride!\n";
    cout << "Would you like to put in a cheat code??\n";
    cout << "Yes or No, Cap Sensitive!\n";
        char y[3];
        cin >> y;
if(y == "Yes"){
        cout << "Please Enter Cheat Code now\n";
        char z[5];

    if(z == "Dog"){
        Dog();
    }else if(z == "Dream"){
        Dream();
    }else if(z == "GTFO"){
        GTFO();
    }else if(z == "Path"){
        Path();
    }else if(z == "Sword"){
        Sword();
    }else if(z == "Weird"){
        Weird();
   }else{
    cout << "Invalid Cheat Code\n";
    }
}else if(y == "No"){

    cout << endl;
    cout << "You wake up and your house is on fire what do you do ??\n";
    cout << "Quick Grab The Dog = 0, GTFO = 1, Go back to sleep = any other number\n";
    int x;
    cin >> x;
    if(x == 0){
        Dog();
    }else if(x == 1){
         GTFO();
    }else{
         Dream();
   }

}else{
cout << "Invalid Answer\n\n\n";
return main();
}
return 0;
}
#包括
//1级
#包括“C:\Users\QuestionMark\Desktop\Make Your Own Adventure\LVL1\Dog.h”
#包括“C:\Users\QuestionMark\Desktop\Make Your Own Adventure\LVL1\Dream.h”
#包括“C:\Users\QuestionMark\Desktop\Make Your Own Adventure\LVL1\GTFO.h”
使用名称空间std;
int main(){

CUT< P>在C++程序中,不允许调用<代码>主代码()/CUT>。
在C中,是的,但是在C++中,没有。当你在程序中调用了“代码>主())/CUT>时,你调用了未定义的行为,程序可能会做任何事情。

< P>在C++程序中,你不允许调用<代码>主()/Cube >句号。
在C中,是的,但是在C++中,没有。当你在程序中调用了“代码>主())/Cube >时,你调用了未定义的行为,程序可以做任何事情。

< P>你不把C字符串与= =。使用StrcMP()来代替。因为这是C++,所以你应该使用STD::字符串。而且,Z(5)还不够大,不能容纳“梦想”。或者其他5个字符串。

你不把C字符串与= =。使用StrcMP()来代替。因为这是C++,所以你应该使用STD::string。同样,Z(5)还不够大,不能保存“梦想”。或者其他5个字符串。

您建议我如何返回main?不要调用它…使用循环!实际上,您可能应该创建一个
std::string GetNextCommand()
函数和一个
DoNextCommand(std::string)
函数。将这两个函数放在一个循环中。可能是一个
do{}while(仍然有效)
loop:)你建议我如何返回main?不要调用它…使用循环!实际上,你可能应该创建一个
std::string GetNextCommand()
函数和一个
DoNextCommand(std::string)
函数。将这两个函数放在一个循环中。可能是一个
do{}while(stillAlive);
loop:)