搜索键在数组中 [英] Search Key In the array

查看:78
本文介绍了搜索键在数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我正在编写一个代码,它将从用户那里获得一个密钥并找到该密钥,天气是否存在于数组中。 。 。

我正在使用VS - 2012,我从未鼓舞过这样的错误..

当我构建项目时,它会提示错误



错误C2181:非法其他没有匹配如果< br /> 
whats''这个错误,,,,,, ,,,,,,,,,,,,,,,,,,,,,, lang =c ++> #include stdafx.h
#include < span class =code-keyword>< iostream >

使用 命名空间标准;

void fill( int a [], int length)
{
for int i = 0 ; i< length; i ++)
{
cout<< 元素#<< i + 1<< ENDL;
cin>> A [1];
}

}

void print( int a [], int length)
{
cout<< R R A Y of 10 Elements ..<< ENDL;
for int j = 0 ; j< length; j ++)
{
cout<< a [j]<< |;
}
}
void find_key( int a [], int length)
{
int key;
cout<< 查找号码:;
cin>>键;
bool found = false ;
for int i = 0 ; i< length; i ++)
{
if (key == a [i])
{
found = true ;
}
if (找到)
{
cout<< K E Y Present<< ENDL;
else
{
cout<< K E Y缺席<< ENDL;

}
}
}
}

int main()
{
const int length = 10 ;
int label [length];
fill(标签,长度);
打印(标签,长度);
find_key(标签,长度);
system( pause);
return 0 ;
}

解决方案

你错过了一个括号:

如果(找到)
{
cout<< K E Y Present<< ENDL;
>>>>
else



你违法了!直接去监狱,不要收取200英镑,就像在Monopoly董事会上所说的那样。

或者你可以放入}


Well I''m writing a code that will get a key from user and find that key, weather it is present in the array or not. . .
I''m using VS - 2012, I''ve never encourtered an error like this ..
when i build the project, it prompts an error

"error C2181: illegal else without matching if"<br />
whats'' this error,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,?



#include "stdafx.h"
#include <iostream>

using namespace std;

void fill(int a[], int length)
{
	for (int i = 0; i < length; i++)
	{
		cout << "Element #" << i+1 << endl;
		cin >> a[i];
	}
	 
}

void print(int a[], int length)
{
	cout << "A R R A Y Of 10 Elements .." << endl;
	for (int j = 0; j < length; j++)
	{
		cout << a[j] << " | ";
	}
}
void find_key(int a[], int length)
	{
		int key;
		cout << "Find The Number: ";
		cin >> key;
		bool found = false;
		for (int i = 0; i < length; i++)
		{
			if (key == a[i])
			{
				found = true;
			}
			if (found)
			{
				cout << "K E Y Present" << endl;
			else
			{
				cout << "K E Y Absent" << endl;
			
			}
		}
	}
}

int main()
{
	const int length = 10;
	int label[length];
	fill(label, length);
	print(label, length);
	find_key(label, length);
	system("pause");
	return 0;
}

解决方案

You missed a bracket here:

if (found)
			{
				cout << "K E Y Present" << endl;
>>>>
			else


"You broke the law! Go directly to jail, do no collect £200" as it says on the Monopoly board.
Or you could just put in the }


这篇关于搜索键在数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆