Array wont compile correctly

I am quite new to C++ and I can't seem to see the problem with my code. I have been working on in this assignment for about 3 days now. Any help will be greatly appreciated.
Here are some output examples.
/*
Enter the size of the array: 5
Enter the numbers in the array, separated by a space, and press enter: 1 5 9 7 3
Enter a number to search for in the array: 9
Found value 9 at index 2 which took 3 checks.

Enter the size of the array: -5
ERROR: you entered an incorrect value for the array size!

Enter the size of the array: 5
Enter the numbers in the array, separated by a space, and press enter: 9 5 1 7 3
Enter a number to search for in the array: 9
Found value 9 at index 0 which took 1 checks.
We ran into the best case scenario!

Enter the size of the array: 5
Enter the numbers in the array, separated by a space, and press enter: 4 5 6 8 2
Enter a number to search for in the array: 2
Found value 2 at index 4 which took 5 checks.
We ran into the worst case scenario!
*/


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #include<iostream>
using namespace std;

int main()
{
    int array_Size,i,j;
    int valueSearch;
    
    cout<<"Please enter the array size desired: ";//asks for the size of desire array
    cin>>array_Size;
    if(array_Size <= 0 )
    {
        cout<<"ERROR: you entered an icorrect value for the array size! "<<endl;
        return 0;
    }
    
    int array[array_Size];
    cout<<"Enter the numbers in the array, separated by a space, and press enter: ";
    for(i = 0; i < array_Size; i++) //Fill array using user's data
    {
        cin>>array[i];

    }
    
    cout<<"Please enter value to search for in array"<<endl;//Asks user which value they would like to search for
    cin>>valueSearch;
    
    for(j = 0; j < array_Size; j++)
    {
        if(valueSearch==array[j])//if value is found
        {
            cout<<"Found value "<<valueSearch<<" at index "<<j<<" which took "<<"HELP"<<" checks."<<endl;
           //break;
        }
        
    }
    
    if(valueSearch == array[0])//if value is found on the first index
    {
        cout<<"We ran into the best case scenario!";
    }
    
    else if (valueSearch == array[array_Size-1])//if value is found on the last index
    {
        cout<<"We ran into the worst case scenario!";
    }
    else if(valueSearch != array[i])
    {
        cout<<"The value "<<valueSearch<<" was not found in the array.";
    }
    cout<<endl;
}


Last edited on
cout<<"Found value "<<valueSearch<<" at index "<<j<<" which took "<<j+1<<" checks."<<endl;
Thank you gunnerfunner.
Topic archived. No new replies allowed.