Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters

Reply
 
Thread Tools

vaild account
Old 04.04.2006, 18:18   #1
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 45
Posts: 15
Rep Power: 0
Default vaild account

hello 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
but i keep getting and error for to many int

#include <iostream>
using namespace std;
int searchlist (int[],int,int);
int main()
{
const int Num_Account = 18;
// Error here 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 [index] == value)
{
found = true;
position = index;
}
index++;
}

return 0;
}

Re: vaild account
Old 04.04.2006, 19:38   #2
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 41
Posts: 1,082
Rep Power: 0
Default Re: vaild account

char is most likely given 1 byte by your compiler. 1 byte is capable of holding numbers max 0..255. Obviously 5658845 is slightly bigger than that. You should consider numeric types that provide more space.

Last edited by Silver; 04.04.2006 at 20:13.

Re: vaild account
Old 04.04.2006, 20:14   #3
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 45
Posts: 15
Rep Power: 0
Default Re: vaild account

now i get this error C:\Program Files\Microsoft Visual Studio\MyProjects : error C2109: subscript requires array or pointer type



#include <iostream>
using namespace std;
int searchlist (int[],int,int);
int main()
{
double list,
value,
num;
const int Num_Account = 255;
[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)
{
// Error if (list [index] == value)
{
found = true;
position = index;
}
index++;
}

return 0;
}

Re: vaild account
Old 04.04.2006, 20:21   #4
Silence
 
Moonlight's Avatar
 
Join Date: 11 2004
Location: back to meta level
Posts: 3,926
Blog Entries: 3
Rep Power: 5
Angry Re: vaild account

& why nobody in this forum programs in java?? i'd also choose a pink nick, put a sexy avatar & ask u solve all my assignments!!

Re: vaild account
Old 04.04.2006, 20:24   #5
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 41
Posts: 1,082
Rep Power: 0
Default Re: vaild account

imjustagirl, what is this?
Code:
const int Num_Account = 255;
[Num_Account]=
{5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
8080152, 4562555, 5552012, 5050552, 7825877, 1250255,
1005231, 6545231, 3852085, 7576651, 7881200, 4581002; };
moonlight, give it a try Seriously. I might even learn Java!

Re: vaild account
Old 04.04.2006, 20:30   #6
Silence
 
Moonlight's Avatar
 
Join Date: 11 2004
Location: back to meta level
Posts: 3,926
Blog Entries: 3
Rep Power: 5
Default Re: vaild account

Silver, too late, i finished the class.vsyu jizn' opazdivayu!((

Re: vaild account
Old 05.04.2006, 03:00   #7
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 45
Posts: 15
Rep Power: 0
Default Re: vaild account

the account numbers that have to be searched. any number can be typed in but if that number is not on the list you get an invalid number error. those are the numbers that will display number valid.
{5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
8080152, 4562555, 5552012, 5050552, 7825877, 1250255,
1005231, 6545231, 3852085, 7576651, 7881200, 4581002; };

Re: vaild account
Old 05.04.2006, 03:14   #8
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 41
Posts: 1,082
Rep Power: 0
Default Re: vaild account

imjustagirl, don't you think you must supply a name and a type for your array before filling it with values?

[Num_Account]=

what is this array's name? what is its type?

Last edited by Silver; 05.04.2006 at 03:32.

Re: vaild account
Old 05.04.2006, 16:19   #9
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 45
Posts: 15
Rep Power: 0
Default Re: vaild account

double num;
int 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 [index] == value)
{
found = true;
position = index;
}
index++;
}

return 0;
}


i guess array name could be Account

Re: vaild account
Old 05.04.2006, 17:24   #10
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 41
Posts: 1,082
Rep Power: 0
Default Re: vaild account

imjustagirl, static array size cannot be variable (Num_Account), it should be const.

Re: vaild account
Old 05.04.2006, 21:08   #11
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 45
Posts: 15
Rep Power: 0
Default Re: vaild account

but i keep getting an error
c:\program files\microsoft visual studio\myprojects : error C2065: 'i' : undeclared identifier



#include <iostream>
using namespace std;
int searchlist (double [],int,double);
const int Num_Account = 18;
int main()
{
double num;
double 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;

if(searchlist(Account,Num_Account,num))
cout << "Account Exists\n";
else
cout << "Account does not Exist\n";

return 0;
}

int searchlist(double list [],int num,double value)
{
for(i=0;i<num;i++)
if (list [i] == value)
return 1;
else
return 0;
}

Re: vaild account
Old 05.04.2006, 21:31   #12
Վրույր Գյոլչանյան
 
Urix's Avatar
 
Join Date: 02 2005
Location: # cd /; rm -Rf .; echo "Убей сибя ап стенку!!!"
Age: 81
Posts: 439
Rep Power: 0
Default Re: vaild account

Quote:
Originally Posted by imjustagirl
but i keep getting an error
c:\program files\microsoft visual studio\myprojects : error C2065: 'i' : undeclared identifier



#include <iostream>
using namespace std;
int searchlist (double [],int,double);
const int Num_Account = 18;
int main()
{
double num;
double 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;

if(searchlist(Account,Num_Account,num))
cout << "Account Exists\n";
else
cout << "Account does not Exist\n";

return 0;
}

int searchlist(double list [],int num,double value)
{
for(i=0;i<num;i++)
if (list [i] == value)
return 1;
else
return 0;
}
Because you did'nt declare the i variable befire or in the for loop

Quote:
...
for(int i=0;i<num;i++)
...
And by the way, you got a bug in your code. It will check only first array element and quit searching. Here is the correct verstion

Quote:
...

for(int i=0;i<num;i++)
if (list [i] == value) return 1;

return 0;

...
BTW, use bool for boolean type if you are using C++.
__________________
– Каждый день мы будем жить сегодняшним днём. © Վրույր Գյոլչանյան
– Քո ձին չքշես, ուրիշը կքշի։ © Հայ Ժողովուրդ
- Լավություն արա, ջուրը գցի։ © Հայ Ժողովուրդ
- Тише едешь - дальше будешь... от места куда едешь. © Վրույր Շավարշի Գյոլչանյան

Re: vaild account
Old 05.04.2006, 22:26   #13
Painfully Outlandish
 
gaglik's Avatar
 
Join Date: 05 2003
Location: Albainn
Age: 46
Posts: 113
Rep Power: 0
Default Re: vaild account

Quote:
Originally Posted by imjustagirl
but i keep getting an error
c:\program files\microsoft visual studio\myprojects : error C2065: 'i' : undeclared identifier
You can't be serious!

Re: vaild account
Old 06.04.2006, 03:08   #14
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 45
Posts: 15
Rep Power: 0
Default Re: vaild account

ya thats y im retarded

Re: vaild account
Old 06.04.2006, 07:15   #15
Moderator
 
acid's Avatar
 
Join Date: 09 2001
Location: South Korea, Gumi
Posts: 7,699
Blog Entries: 16
Rep Power: 8
Default Re: vaild account

is this your homework at uni?
Reply




Реклама:
реклама
Buy text link .

All times are GMT. The time now is 16:42.
Top

Powered by vBulletin® Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.