- 已关闭**。此问题需要details or clarity。当前不接受答案。
- 想要改进此问题?**添加详细信息并通过editing this post阐明问题。
昨天关门了。
Improve this question
在我的程序中,我使用了一个迷宫的图片作为参考,并从中创建了方向。我的第一次输入似乎很顺利,但从那里开始就变得忙碌起来,因为它输出了我在迷宫中特定位置的每一个cout。我不确定我做错了什么。我是c++的新手,正在遵循在线教程。所以请你友善一点,因为我只是想学一门新的技能。2下面是我正在使用的迷宫的图片,以供参考。
我一直在使用if语句来尝试和导航用户。它是半工作的,但我似乎在某个地方犯了错。
下面是我的代码:
#include <iostream>
using namespace std;
int main()
{
int choice;
cout << endl;
cout << "Welcome to the Maze Challenge! Your goal is to navigate your way through the maze by moving left or right to victory!";
cout << endl << endl;
cout << "To move right please use 1, and to move left please use 0";
cout << endl << endl;
cout << "Your are starting at Position 1. Would you like to turn right or left?: ";
cin >> choice;
//Position 1
if (choice == 1){
cout << "You are now at Position 3. Would you like to turn right or left?: ";
cin >> choice;
}
//Position 2
if (choice == 0){
cout << "You are now at Position 2. Would you like to turn right or left?: ";
cin >> choice;
}
if (choice == 1) {
cout << "Sorry! You have landed in dead end X1. Good luck next time!" << endl;
}
if (choice == 0) {
cout << "Sorry! You have landed in dead end X2. Good luck next time!" << endl;
}
//Position 3
if (choice == 1) {
cout << "You are now at Position 4. Would you like to turn right or left?: ";
cin >> choice;
}
if (choice == 0) {
cout << "Sorry! you have landed in dead end X3. Good luck next time!" << endl;
}
//Position 4
if (choice == 1) {
cout << "You are now at Position 5. Would you like to turn right or left?: ";
cin >> choice;
}
if (choice == 0) {
cout << "You are now at Position 7. Would you like to turn right or left?: ";
}
下面是输出:
1条答案
按热度按时间vdzxcuhz1#
定义迷宫数据,以便从当前位置确定2个目的地(左和右)。
例如非常简单......
使用此数据,代码可以编写为: