我正在制作这个小程序。在lamens术语中,我想要制作一个用户可以输入他的选择的菜单,它将他带到预定区域,并且在他完成之后将他带回菜单,在那里他可以做出不同的选择。当你按下1时,我已经显示它显示的位置(你会看到我对代码的意思)。但是在经历了它应该做的事情之后,它不会回到菜单,只是继续第二个选项。还要说你在菜单上,你想从第一个选项开始第二个选项。任何人都可以帮助我...
#include <iostream>
using namespace std;
int main()
{
int option;
cout << "Hello there...\n\nToday we are going to do a little fun project that I created.\n\n";
cin.get();
cout << "\nAs we progress throughout this program, I will explain the different things\n";
cout << "that we are going to do. We will be covering some basic C++ excersises.";
cout << "\n\nFirst and foremost we will begin by covering what I have learned so far....\n\n";
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 << "\n\n\nEnter the number of one of the following and I will explain!\n";
cout << "1.integer 2.boolian 3.floats 4.doubles 5.character";
cout << "\n\n[when you are done type 'done' to continue]\n\n";
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 << "\n\n\nInteger is the variable abbreviated as 'int' this allows C++ to only";
cout << "\nread whole and real numbers. C++ takes this number as stores it\n";
cout << "in a user-defined variable (you can make up what that variable is..)\n";
cin.get();
cout << "an example syntax would be:";
cout << "\n\nint var=[whole;real number]";
cin.get();
cout << "\n\nwhat 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 number\ninside of it.";
cout << "\n\nPress any key to go back to menu";
cin.get();
}
else if (option = 2); //continues with this without going back to menu.
{
cin.ignore();
cout << "\n\n\nBoolian 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 it\n";
cout << "in a user-defined variable (you can make up what that variable is..)\n";
cin.get();
cout << "an example syntax would be:";
cout << "\n\nbool var=[true or false]";
cin.get();
cout << "\n\nwhat 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 false\ninside of it.";
cout << "\n\nPress any key to go back to menu";
cin.get();
}
} while (var = 1);
}
答案 0 :(得分:1)
问题在于比较运算符
1)if (option = 1)
,使用if(option == 1)
2)else if (option = 2);
,使用else if(option == 2)
,删除分号
3)while(var = 1) ;
,使用while(var ==1 );
答案 1 :(得分:0)
C ++中的比较是使用==运算符完成的: e。
if (option == 1)
if (option == 2)
while (var == 1);