我正在创建一个 c++ 数组程序,在该程序中我试图从用户那里获取输入,但在插入过程中我想提示用户输入重复值。我在里面使用了一个while循环和for循环,但是如果用户输入了重复的值,它就不起作用了。他将被要求在特定索引处再次输入值。
int size=0;
int k;
int index=0;
int temp=0;
int aray1[2];
char ch='y';
while(ch='y') {
for(k=0; k<=2; k++)
{
if(aray1[k]==temp) {
cout<<"please do not enter duplicates";
ch='y';
index--;
} else {
aray1[index]=temp;
index++
ch='n';
}
}
system("pause");
}