我不明白为什么这个函数不起作用
I don't understand why this function isn't working
这是我正在创造的一款简单的基于文本的游戏,从菜单开始。我希望人们能够在按下'p'时玩游戏,但这个游戏功能不起作用。
#include <iostream>
#include <string>
using namespace std;
void menu()
{
char menuResponse;
cout << "[P]lay [O]ptions [C]reditsn";
cin >> menuResponse;
if (menuResponse == 'p')
{
game();
}
else if (menuResponse == 'o')
{
cout << "There's actually nothing to see here, sorry.n";
char optionResponse;
cout << "[B]ackn";
cin >> optionResponse;
menu();
}
else if (menuResponse == 'c')
{
cout << "Created by Crusader Studios, 2014n";
char creditResponse;
cout << "[B]ackn";
cin >> creditResponse;
menu();
}
else
{
cout << "Please type a valid letter.n";
menu();
}
}
void game()
{
cout << "tttProloguenn";
}
int main()
{
cout << "ttWelcome to my first game, 'A Hero's Journey!'nn";
cout << "To navigate through menus, type the letters inside the brackets. For example,n";
cout << "pressing 'p' in a menu with [P]lay and [O]ptions will let you play.nn";
char beginResponse;
cout << "Do you understand? If so, press any key:n";
cin >> beginResponse;
cout << "Great! Now we can begin our game!n";
menu();
return 0;
}
游戏函数为void game(),菜单为void menu()。
您还没有声明函数…
void game();
在void menu()
函数前声明
void game();
void menu()
{
//... code
}
你需要在使用它之前给出函数的原型,因此我们需要在C/c++中主要使用头文件。
所以在使用之前,if (menuResponse == 'p'){游戏();}
你应该声明prototype。
void game();
....
if (menuResponse == 'p')
{
game();
}
相关文章:
- 仅包含可移动 std::map 的类的移动构造函数不起作用
- 为什么我的数组双精度函数不起作用?
- std::函数不起作用,但普通的旧函数指针可以 - 为什么?
- C++ Arduino - 随机函数不起作用
- 为什么我的数组或函数不起作用?
- 从类中的另一个文件请求函数不起作用
- 双链表堆栈删除函数不起作用
- 将 cmake 代码段转换为函数 - 不起作用
- 为什么我的从base64解码的函数不起作用?
- 为什么当我们使用等于'='符号比较器函数时,c ++的内置排序函数不起作用?
- swap(int&, int&) 函数不起作用,当交换不使用临时变量时?
- 子类化 STL 容器:范围构造函数不起作用
- 带有此指针的模板类多重继承构造函数不起作用?
- 以下打印树函数不起作用为什么?
- 为什么内存集函数不起作用?
- 调用填充我的主体数组的函数不起作用
- 带有自定义数字的阶乘函数不起作用
- 如何QDialog raise()函数不起作用
- Lambda 表达式闭包函数不起作用
- C++:在没有 lvalue 的情况下调用时复制构造函数不起作用