473,396 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Linear search

hi guys can some one help me here
i have to accept a number
and preform a linear search for the numbers

and if its not one of the number it has to say its invalid
#include <iostream>
using namespace std;
int searchlist (int[],int,int);
int main()
{
const int Num_Account = 18;
char Account[Num_Account]=
{"5658845, 4520125", "7895122, 8777541",
"8451277, 1302850",
"8080152, 4562555", "5552012, 5050552",
"7825877, 1250255",
"1005231, 6545231", "3852085, 7576651",
"7881200, 4581002" };

cout << "enter Number\n";
cin >> num;

int searchlist(int list [],int num,int value)
{
int index = 0;
int position = -1;
bool found = false;

while (index < num &&!found)
{
if (list == value)
{
found = true;
position = index;
}
index++;
}

return 0;
}

Apr 5 '06 #1
2 3931
* littlegirl:
hi guys can some one help me here
i have to accept a number
and preform a linear search for the numbers

and if its not one of the number it has to say its invalid
#include <iostream>
using namespace std;
int searchlist (int[],int,int);
int main()
{
const int Num_Account = 18;
char Account[Num_Account]=
{"5658845, 4520125", "7895122, 8777541",
"8451277, 1302850",
"8080152, 4562555", "5552012, 5050552",
"7825877, 1250255",
"1005231, 6545231", "3852085, 7576651",
"7881200, 4581002" };

cout << "enter Number\n";
cin >> num;

int searchlist(int list [],int num,int value)
{
int index = 0;
int position = -1;
bool found = false;

while (index < num &&!found)
{
if (list == value)
{
found = true;
position = index;
}
index++;
}

return 0;
}


Try first of all to move the definition of the 'searchlist' function to
/above/ the 'main' function: C++ does not support direct nesting of
function definitions.

When you've moved the definition, remove the declaration of 'searchlist'
that you now have after your 'using' directive, and in general, avoid
declaring functions that you define later on.

In 'main' you need to call 'searchlist', and present the result of that
call.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Apr 5 '06 #2
"Alf P. Steinbach" writes:

<one added point>
i have to accept a number and preform a linear search for the numbers

and if its not one of the number it has to say its invalid
#include <iostream>
using namespace std;
int searchlist (int[],int,int);
int main()
{
const int Num_Account = 18;
char Account[Num_Account]= {"5658845, 4520125", "7895122, 8777541",
"8451277, 1302850",
"8080152, 4562555", "5552012, 5050552",
"7825877, 1250255",
"1005231, 6545231", "3852085, 7576651",
"7881200, 4581002" };

cout << "enter Number\n";
cin >> num;

int searchlist(int list [],int num,int value)
{
int index = 0;
int position = -1;
bool found = false;

while (index < num &&!found)
{
if (list == value)
{
found = true;
position = index;
}
index++;
}
You promised to return an int. Remember? There is no way for the caller to
determine what happened.

An int works fine, but the more modern way is to return a bool, it has
better self-documenting properties than an int.
return 0;
}


Try first of all to move the definition of the 'searchlist' function to
/above/ the 'main' function: C++ does not support direct nesting of
function definitions.

When you've moved the definition, remove the declaration of 'searchlist'
that you now have after your 'using' directive, and in general, avoid
declaring functions that you define later on.

In 'main' you need to call 'searchlist', and present the result of that
call.



Apr 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Scott David Daniels | last post by:
I am sorry, but in the Python 2.4 description of "heapify", I find the description of "Transform list x into a heap, in-place, in linear time," unbelievable. I understand the hand-wave that makes...
2
by: leo | last post by:
I am looking for a source code for solving linear programming using simplex method. if any one of you have any code related to it in C,C++ or JAVA then please send it to me immediately.
3
by: sql guy123 | last post by:
This is a real challenge. I hope someone is smart enough to know how to do this. I have a table TABLE1
4
by: mano | last post by:
Hello.... Can anybody give me some idea ... How to write programs on (...(In C++)) Gauss elimination LU Decomposition finding Inverse Thanks
3
by: ntuyen01 | last post by:
Hi All, Does anyone has examples for Linear Regression formula using c#. Or any good third party software create this. Thanks in advance Regards, Ted
1
by: geebanga88 | last post by:
HI i have a method that performs a linear search to find a given vowel. The vowel parameter is a given vowel, while vowel is the array with all the vowels. public static void...
3
by: jivelasquezt | last post by:
Hi all, I'm new to this group so I don't know if this question has been posted before, but does anyone knows about linear/integer programming routines in Python that are available on the web,...
3
by: nembo kid | last post by:
I have an issue with a simple function that has to make a linear search for a key into an array. If the key is found in the array, the function it has to return 1 to the caller and pass array...
4
by: Evelien | last post by:
Dear python-users, I am trying to do a non-linear least squares fitting. Maybe trying is not the best word, as I already succeeded in that. At the moment I am using leastSquaresFit from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.