Array Problem

I am trying to find the max of array and the index.

the code below: when i try to run it. it show me nothing.

how can i fix it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

int main ()
{
    int number [5];
    int max = 0;
    
    for (int i = 0 ; i < 5 ; i++)
    {
        if (number [i] > max)
        {
            max = number [i];
            
        }
    }
    return 0;
    
}
1. You do use the array uninitialized, so you are looking at undefined values. Perhaps you should get real numbers from somewhere before searching for max?

2. Pretending that you already ask numbers from user, I type negative numbers. 0 is no longer the correct answer.

3. How do you fix a code that does not produce any output? You add statements that do produce output.
Topic archived. No new replies allowed.