K
K
korolmig2020-09-30 21:16:29
C++ / C#
korolmig, 2020-09-30 21:16:29

How to fix the error in this code?

#include <iostream>
using namespace std;

int main()
{
    const int N = 5;
    float A[N], C[N];
    float MIN, MIN2, X;
    int i;
    i = 0;
    A[0] = MIN;
    C[0] = MIN2;
    for (i; i < N; i++)
    {
        cout << "VVOD A:";
            cin >> A[N];
            cout << "VVOD C:";
            cin >> C[N];
    }
    for (i=1; i < N; i++)
    {
        if (A[i] < MIN)
        {
            MIN = A[i];
        }
    }
    for (i = 1; i < N; i++)
    {
        if (C[i] < MIN2)
        {
            MIN2 = C[i];
        }
    }
    X = (MIN + MIN2) / 2;
    cout << "sredne arifmeticeskoe naimenshih:" << X;

}


the program should calculate the arithmetic mean of the smallest elements of arrays A and C.

This is the error
C6001 gives: use of uninitialized memory MIN2 MIN

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stepka1984, 2020-09-30
@Stepka1984

The MIN variable is not initialized, while you use it in the condition. Same thing with MIN2. Give them initial values

O
olkhovichs, 2020-09-30
@olkhovichs

You are assigning the first element of your array the value of an uninitialized variable. Here:A[0]MIN

A[0] = MIN;

Further in the same way with another array.

E
Evgeny Petryaev, 2020-09-30
@Gremlin92

Swap min1 and a(0) and min2 and c(0)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question