![]() |
![]() | #1 |
Младенец Join Date: 03 2006 Location: san fan Age: 39
Posts: 15
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]()
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; } |
![]() |
![]() | #2 |
Easy rider Join Date: 11 2005 Location: tristeza Age: 36
Posts: 1,082
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]()
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. |
![]() |
![]() | #3 |
Младенец Join Date: 03 2006 Location: san fan Age: 39
Posts: 15
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]()
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; } |
![]() |
![]() | #5 |
Easy rider Join Date: 11 2005 Location: tristeza Age: 36
Posts: 1,082
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]() 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; }; ![]() |
![]() |
![]() | #7 |
Младенец Join Date: 03 2006 Location: san fan Age: 39
Posts: 15
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]()
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; }; |
![]() |
![]() | #8 |
Easy rider Join Date: 11 2005 Location: tristeza Age: 36
Posts: 1,082
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]()
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. |
![]() |
![]() | #9 |
Младенец Join Date: 03 2006 Location: san fan Age: 39
Posts: 15
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]()
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 |
![]() |
![]() | #11 |
Младенец Join Date: 03 2006 Location: san fan Age: 39
Posts: 15
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]()
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; } |
![]() |
![]() | #12 | |||
Վրույր Գյոլչանյան Join Date: 02 2005 Location: # cd /; rm -Rf .; echo "Убей сибя ап стенку!!!" Age: 75
Posts: 439
Downloads: 1 Uploads: 0
Reputation: 0 | 0 | ![]() Quote:
Quote:
Quote:
![]()
__________________ – Каждый день мы будем жить сегодняшним днём. © Վրույր Գյոլչանյան – Քո ձին չքշես, ուրիշը կքշի։ © Հայ Ժողովուրդ - Լավություն արա, ջուրը գցի։ © Հայ Ժողովուրդ - Тише едешь - дальше будешь... от места куда едешь. © Վրույր Շավարշի Գյոլչանյան | |||
![]() |
![]() | #13 | |
Painfully Outlandish Join Date: 05 2003 Location: Albainn Age: 41
Posts: 113
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]() Quote:
![]() | |
![]() |
![]() | #14 |
Младенец Join Date: 03 2006 Location: san fan Age: 39
Posts: 15
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]()
ya thats y im retarded
|
![]() |