Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 交叉检查整数列表中的整数运行时错误_C++_Visual Studio_If Statement_Visual C++_Runtime Error - Fatal编程技术网

C++ 交叉检查整数列表中的整数运行时错误

C++ 交叉检查整数列表中的整数运行时错误,c++,visual-studio,if-statement,visual-c++,runtime-error,C++,Visual Studio,If Statement,Visual C++,Runtime Error,以下代码已尽可能简化,并假定要执行以下操作: 1) 用户填充5个整数的列表 2) 用户输入一个“数字” 3a)如果“数字”与5个整数中的一个相同-将显示该数字的两倍,然后重复2 3b)如果“数字”与5个整数中的一个不同,则结束程序 但是,在运行时,我输入列表中的一个数字,并得到输出响应,表示它不在列表中。此外,如果激活此else语句,则while循环将在a=0时停止,但它将继续循环 以下是我认为错误在于列表中未显示的编号: if (number == list[x]) 我可能在括号内使用了错误

以下代码已尽可能简化,并假定要执行以下操作:

1) 用户填充5个整数的列表

2) 用户输入一个“数字”

3a)如果“数字”与5个整数中的一个相同-将显示该数字的两倍,然后重复2

3b)如果“数字”与5个整数中的一个不同,则结束程序

但是,在运行时,我输入列表中的一个数字,并得到输出响应,表示它不在列表中。此外,如果激活此else语句,则while循环将在a=0时停止,但它将继续循环

以下是我认为错误在于列表中未显示的编号:

if (number == list[x])
我可能在括号内使用了错误的语句

但是我不知道为什么它还会继续循环,也许这两个错误都是因为同一件事。如能提供上述程序运行方面的任何帮助,我们将不胜感激

以下是完整的代码:

#include <iostream>
using namespace std;
int main()
{
int list[5];
int a, x, number;
a = 1;
cout << "Fill up the list" << endl;
for (x = 0; x <= 4; x++){
    cin >> list[x];
    }

while (a = 1) {

cout << "enter one of the numbers you put on the list" << endl;
cout << "we will double it " << endl;
cin  >> number ;
if (number == list[x])
{
    cout << "double that number is " << number * 2 << endl;
}
else
{
    cout << "Thats not on the list" << endl;
    a = 0;
}
}

return 0;
}
#包括
使用名称空间std;
int main()
{
国际清单[5];
int a,x,数字;
a=1;
难道我变了吗

if (number == list [x])

改变

while (a = 1)

但是如果有人知道一个替代方案而不是

if ((number == list[0])||(number == list[1])|| (number == list[2]) || (number == list[3])||(number == list[4]))
我愿意接受建议

完整代码现在是:

#include <iostream>
using namespace std;
int main()
{
int list[5];
int a, x, number;
a = 1;
cout << "Fill up list bitch" << endl;
for (x = 0; x <= 4; x++){
    cin >> list[x];
    }

while (a == 1) {

cout << "enter one of the numbers you put on the list" << endl;
cout << "we will double it " << endl;
cin  >> number ;
if ((number == list[0])||(number == list[1])|| (number == list[2]) || (number == list[3])||(number == list[4]))
{
    cout << "double that number is " << number * 2 << endl;
}
else
{
    cout << "Thats not on the list you scumbag" << endl;
    a = 0;
}
}

return 0;
#包括
使用名称空间std;
int main()
{
国际清单[5];
int a,x,数字;
a=1;

cout提示:x的值是多少?我猜x=4对吗?
if ((number == list[0])||(number == list[1])|| (number == list[2]) || (number == list[3])||(number == list[4]))
#include <iostream>
using namespace std;
int main()
{
int list[5];
int a, x, number;
a = 1;
cout << "Fill up list bitch" << endl;
for (x = 0; x <= 4; x++){
    cin >> list[x];
    }

while (a == 1) {

cout << "enter one of the numbers you put on the list" << endl;
cout << "we will double it " << endl;
cin  >> number ;
if ((number == list[0])||(number == list[1])|| (number == list[2]) || (number == list[3])||(number == list[4]))
{
    cout << "double that number is " << number * 2 << endl;
}
else
{
    cout << "Thats not on the list you scumbag" << endl;
    a = 0;
}
}

return 0;