| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Memory & arrays - Array Position
ok this is my scenario:
A program which reads and stores in an array 10 integers from the command line, and then prompts the user to enter a single integer from standard input.then prints out the the position at which is the integer. It's all good...except that i can't figure out how to print out the actual position. I was thinking 'switch' but what if i got 100 numbers tha's my code so far: void main(int argc,char* argv[]) { int numbers[10]; int input; for ( int count=0; count<10; count++ ) { numbers[count]=atoi(argv[count+1]); } cout<<"Enter Number: "<<endl; cin>>input; if( input!=numbers[0,1,2,3,4,5,6,7,8,9]) { cout<<"Not Found"<<endl; } else // that's where the problem comes { cout<<"Found at Position: "; } } Any ideas? ![]() |
|
#2
|
|||
|
|||
|
Code:
if( input!=numbers[0,1,2,3,4,5,6,7,8,9])
{
cout<<"Not Found"<<endl;
}
I'd add to you input validation: cout << "Invalid Number, Please enter a new one: "; cin >> input; that is all I got though really |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Memory & arrays - Array Position |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|