Hi
i created a program but I have an error about an assertion failure. Any ideas on how to correct this?
I get the error failed assertion `1 <= number[i] && number[i] <= 1000'Code:#include <iostream> #include <cstdlib> #include <cassert> using namespace std; int main(int argc, char* argv[]) { int n; // number that the user enters int i; // used to iterate through an array int number[10]; // array to store the 10 command line inputs int index = -1; // index at which the integer is found bool found = false; // flag that tells whether the search was successful //Check to see if the command line input was correct if( argc != 11 ) { cerr << "Usage: n1 n2 n3 n4 n5 n6 n7 n8 n9 n10\n" ; exit(1) ; } //Store the 10 command line integers for ( i = 0; i < 10; i++ ) { number[i] = atoi( argv[i+1] ) ; assert( 1 <= number[i] && number[i] <= 1000 ) ; } //User enters integer to be searched cout << "Enter Number: " << endl ; cin >> n; //Loop through the array and look for the integer for ( i = 0; i < 10; i++ ) { if ( n == number[i] ) { index = i; found = true; break; } } //Display result if ( found ) cout << "\nFound at index: " << index << endl; else cout << "\nNOT FOUND" << endl; return 0; }
Abort
Any ideas to correct this would be great.