嘿伙计们,我是 C++ 新手,为了练习我正在制作一个“制作自己的冒险游戏”我不知道问题是什么我相信它主要与我的 char 变量有关我将发布代码我的 main.cpp 怎么会有其他外部头文件但我认为没有理由发布它们我的代码也将运行而不会给我一个错误,如果我的 if else 语句被破坏/我的字符变量。
谢谢您的帮助。
#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;
}
在旁注中。在 The Header Dog 中,我调用了 level2 的所有函数,我只是想知道为什么我的程序运行良好,而无需我调用 GTFO 标题和 Dream 标题中的所有 level2 函数。
ps: 只是为了消除一些混淆 Path();,Sword();, 和 Weird(); 都是level2函数。
pps:也只是想知道为什么我不必在 main.cpp 中调用 level2 函数?
最后的想法:感谢您的时间,祝您有美好的一天!
ps 最后的想法:这是一个传送门 1 参考。