Armenian Knowledge Base  

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

Reply
 
LinkBack Thread Tools
Old 04.04.2006, 19:18   #1
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 36
Posts: 15
Downloads: 0
Uploads: 0
Reputation: 0 | 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;
}
Reply With Quote
Old 04.04.2006, 20:38   #2
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 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 21:13.
Reply With Quote
Old 04.04.2006, 21:14   #3
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 36
Posts: 15
Downloads: 0
Uploads: 0
Reputation: 0 | 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;
}
Reply With Quote
Old 04.04.2006, 21:21   #4
Silence
 
Moonlight's Avatar
 
Join Date: 11 2004
Location: back to meta level
Posts: 3,926
Downloads: 1
Uploads: 0
Blog Entries: 3
Reputation: 202 | 3
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!!
Reply With Quote
Old 04.04.2006, 21:24   #5
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 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!
Reply With Quote
Old 04.04.2006, 21:30   #6
Silence
 
Moonlight's Avatar
 
Join Date: 11 2004
Location: back to meta level
Posts: 3,926
Downloads: 1
Uploads: 0
Blog Entries: 3
Reputation: 202 | 3
Default Re: vaild account

Silver, too late, i finished the class.vsyu jizn' opazdivayu!((
Reply With Quote
Old 05.04.2006, 04:00   #7
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 36
Posts: 15
Downloads: 0
Uploads: 0
Reputation: 0 | 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; };
Reply With Quote
Old 05.04.2006, 04:14   #8
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 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 04:32.
Reply With Quote
Old 05.04.2006, 17:19   #9
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 36
Posts: 15
Downloads: 0
Uploads: 0
Reputation: 0 | 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
Reply With Quote
Old 05.04.2006, 18:24   #10
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: vaild account

imjustagirl, static array size cannot be variable (Num_Account), it should be const.
Reply With Quote
Old 05.04.2006, 22:08   #11
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 36
Posts: 15
Downloads: 0
Uploads: 0
Reputation: 0 | 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;
}
Reply With Quote
Old 05.04.2006, 22:31   #12
Վրույր Գյոլչանյան
 
Urix's Avatar
 
Join Date: 02 2005
Location: # cd /; rm -Rf .; echo "Убей сибя ап стенку!!!"
Age: 72
Posts: 439
Downloads: 1
Uploads: 0
Reputation: 0 | 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++.
__________________
– Каждый день мы будем жить сегодняшним днём. © Վրույր Գյոլչանյան
– Քո ձին չքշես, ուրիշը կքշի։ © Հայ Ժողովուրդ
- Լավություն արա, ջուրը գցի։ © Հայ Ժողովուրդ
- Тише едешь - дальше будешь... от места куда едешь. © Վրույր Շավարշի Գյոլչանյան
Reply With Quote
Old 05.04.2006, 23:26   #13
Painfully Outlandish
 
gaglik's Avatar
 
Join Date: 05 2003
Location: Albainn
Age: 37
Posts: 113
Downloads: 0
Uploads: 0
Reputation: 0 | 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!
Reply With Quote
Old 06.04.2006, 04:08   #14
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 36
Posts: 15
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: vaild account

ya thats y im retarded
Reply With Quote
Old 06.04.2006, 08:15   #15
Moderator
 
acid's Avatar
 
Join Date: 09 2001
Location: South Korea, Gumi
Posts: 7,699
Downloads: 102
Uploads: 34
Blog Entries: 16
Reputation: 561 | 6
Default Re: vaild account

is this your homework at uni?
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 16:38.


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