有关操作员的简单查询
Simple query regarding operators
您好,我正在编写一个程序,该程序运行了许多基于用户输入的菜单选择运行的功能,我将不包括。我的问题是,为什么以下代码不响应用户输入的差异。例如,如果我输入菜单选择1或4,它无关紧要,并且会恢复为菜单选择1。我知道它与我的=或==操作员有关,但都没有产生正确的结果,所以我不确定该如何做。请帮助!
int main() //Handles the if statements concerning the menu of the program
{
int r_identifier[42]; //Variable Declaration
int year_entry[42];
double gpa_entry[42];
string student_name[42];
int index = 0;
int menuchoice; //Variable Declaration
do
{
print_menu(); //Calls function to print menu
get_selection(menuchoice); //Calls function to get the menu selection
if (menuchoice = 1) //Calls the function to input a new user
{
input_new_student(student_name, r_identifier, gpa_entry, index, year_entry);
cout << "nThe student with R#" << r_identifier[index] << " was created. " << endl;
index++;
}
else if (menuchoice = 2) //Prints all
{
print_all ();
}
else if (menuchoice = 3) //Prints statistics about all students in a particular year
{
int year_view;
print_by_year(student_name, r_identifier, gpa_entry, index, year_entry);
}
else if (menuchoice = 4) //Prints statistics about all entered users
{
print_statistics();
}
else if (menuchoice = 5) //Quits the program
{
cout << "Have a good summer! ";
cout << endl;
}
} while (menuchoice != 5);
return 0;
}
1 。'='是用于分配的 例如:int a = 5分配5个名为a。
的变量在您的情况下... u应该更改所有ur'=''=='。'=='是用于比较。例如:if(a==5)cout<<a;
仅在a等于5 ...
2 变量menuchoice不采用一个值... u不应该将其作为函数getSelection的参数...相反,您可以让它返回类似于此 menuchoice=getselection()
3 包括其他部分...它为整个程序提供了更多的含义,而不是在...保持尽可能简单:)
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 在c++中用vector填充一个简单的动态数组
- 查询SQLite数据库中的日期
- (C++)分析树以计算返回错误值的简单算术表达式
- 我的简单if-else语句是如何无法访问的代码
- 使用简单类型列表实现的指数编译时间.为什么
- mysql_query()带有简单的查询segfault
- 有关操作员的简单查询
- 如何查询简单机器论坛以获取主题受欢迎程度/评级
- 超简单C++构造函数查询
- 查询简单C++线程池实现
- C++的简单输入/输出查询
- 关于条件C++如何执行的简单查询
- 关于运算符重载的查询,复数上的简单代码示例,添加
- 在终止/非活动会话上执行简单查询需要几分钟时间
- 指针基础:一个简单的查询
- 如何从Linux上的c++连接并执行一个简单的查询到SQL Server
- 为HTTPS查询返回简单字符串的c++库
- SQL Server Compact Edition 3.5 为简单查询提供"Multiple-step operation generated errors"错误
- "Access violation" 显示简单 Oracle 查询字符串时出错 (VS10 Exp C++)