菜单结构和循环
Menu Structure and Loops
我有一个我正在创建的小程序。用Lamens的话来说,我想制作一个菜单,用户可以输入他的选择,将他带到预定的区域,完成后,他将他带回菜单,在那里他可以做出不同的选择。当您按1时,我已经降低了它显示的位置(您将看到我对代码的意思)。但是,在经历了应该做的事情之后,它不会返回菜单,它继续延续到第二个选项。另请说您在菜单上,您想从第二个选项开始,它只是从第一个开始。任何人都可以帮我...
#include <iostream>
using namespace std;
int main()
{
int option;
cout << "Hello there...nnToday we are going to do a little fun project that I created.nn";
cin.get();
cout << "nAs we progress throughout this program, I will explain the different thingsn";
cout << "that we are going to do. We will be covering some basic C++ excersises.";
cout << "nnFirst and foremost we will begin by covering what I have learned so far....nn";
cin.get();
cout << "The first topic we will cover will include what is known as 'variables'.n";
cout << "what are variables you ask?";
cin.get();
int var = 1;
int main=1;
do
{
cout << "nnnEnter the number of one of the following and I will explain!n";
cout << "1.integer 2.boolian 3.floats 4.doubles 5.character";
cout << "nn[when you are done type 'done' to continue]nn";
cin >> option; //this is where the user puts in his option (1,2,3,4,5,6) I have only 1 and 2 complete
if (option = 1) //starts with this regardless of input
{
cin.ignore();
cout << "nnnInteger is the variable abbreviated as 'int' this allows C++ to only";
cout << "nread whole and real numbers. C++ takes this number as stores itn";
cout << "in a user-defined variable (you can make up what that variable is..)n";
cin.get();
cout << "an example syntax would be:";
cout << "nnint var=[whole;real number]";
cin.get();
cout << "nnwhat this implies is that you have 'declared' to the system";
cout << "nthat you are going to use an 'int' that you have named 'var'n";
cout << "and in this 'var' you are going to store a real and whole numberninside of it.";
cout << "nnPress any key to go back to menu";
cin.get();
}
else if (option = 2); //continues with this without going back to menu.
{
cin.ignore();
cout << "nnnBoolian is the variable abbreviated as 'bool' this allows C++ to only";
cout << "nread true or false ( 0 or 1 ). C++ takes this number as stores itn";
cout << "in a user-defined variable (you can make up what that variable is..)n";
cin.get();
cout << "an example syntax would be:";
cout << "nnbool var=[true or false]";
cin.get();
cout << "nnwhat this implies is that you have 'declared' to the system";
cout << "nthat you are going to use an 'bool' variable that you have named 'var'n";
cout << "and in this 'var' you are going to store a either a true or falseninside of it.";
cout << "nnPress any key to go back to menu";
cin.get();
}
} while (var = 1);
}
问题在于比较操作员
1)if (option = 1)
,使用if(option == 1)
2)else if (option = 2);
,使用else if(option == 2)
,删除分号
3)while(var = 1) ;
,使用while(var ==1 );
C 中的比较是用==操作器进行的:
例如。
if (option == 1)
if (option == 2)
while (var == 1);
相关文章:
- 如何循环打印顶点结构
- 在基于范围的for循环中使用结构化绑定声明
- 在C++中循环访问自定义结构列表的小问题
- C++ - 使用用户输入的字符串数据检查结构字符串数据(无限执行 while 循环)
- 输入 ctrl + x 后如何再次 cin (cin<<x) 循环(cin 一个结构)
- 类方法 - 数据结构中 For 循环的运行时错误
- 用于循环访问多个集合的数据结构
- 将结构数据存储在循环缓冲区中
- 为什么基于范围的 for 循环中的结构化绑定只是一个副本而不是引用?
- for 循环说 - 错误 成员引用基类型"int [13]"不是结构或联合
- 循环依赖结构,使用前向声明时结构的错误重定义
- 如何在 for 循环中声明和使用结构数组?
- 在C++中循环数组时访问结构属性
- 在 for 循环中声明结构是否合法C++?
- C++ 数据结构队列:使用 for 循环查找队列中最大的元素
- 简化C++中的嵌套循环结构
- 如何与多个内核一起使用模板循环结构
- 数组循环结构
- C++循环结构问题
- c++ for循环结构