Search code examples
c++undefinedidentifier

It keeps saying identifier "posi" is undefined


It keeps saying identifier "posi" is undefined for some reason, searched for it but found nothing similar, can anybody help? the code is below, im new to programming, and not that familiar with c++, help would be appreciated, thank you.

#include "stdafx.h"
#include <iostream>
#include <math.h>

using namespace std;

const int num = 10;

int max[num], sum[num], min[num];
int total(int sum[], int num);
int maximum(int max[], int num, int posi[]);
int minimum(int min[], int num, int posi[]);

int main() {
    int i, pnum, psum, pmax, pmin;
    cout << "Give 10 positive integer values, one-by-one: " << endl;
    while (num > 0) {

        for (i = 0; i < 11; i++) {
            cout << "Enter Number" << i << ":";
            cin >> pnum;

        }

    }
    psum = total(sum, num);
    cout << "The sum is " << sum;
    cin >> sum[i];
    pmax = maximum(max, num, posi);
    cout << "The maximum value is " << max << ", and it is in position " << 
    posi << endl;
    cin >> max[i] >> posi[i];
    pmin = minimum(min, num, posi);
    cout << "The minimum value is " << min << ", and it is in position " << 
    posi << endl;
    cin >> min[i] >> posi[i];
    system ("pause");
    return 0;
    }

        int maximum(int max[], int num, int posi[]) {
        int posit = 0, maxi = 0, numb,i;
        maxi = numb;
        while (numb > 0) {
            for (i = 0; i < 11; i++) {
                if (numb > maxi) {
                    maxi = numb;
                    posit = i;

                }
                i = i + 1;
            }
            return maxi;
        }
        }

Solution

  • It's saying that it's undefined because you never define it. In this function call pmax = maximum(max, num, posi); you're passing posi to maximum, but you haven't defined it yet! The reason you get the error for the call to maximum and not minimum is probably because the compiler stops compiling once it hits the undefined reference. If you remove the call to maximum it'll give you an error when you try to do cin >> max[i] >> posi[i];. If you remove that line, then it'll give you an error when you call minimum, and so forth. I'd suggest checking out some basic C++ tutorials, these ones are pretty good. Specifically the Variables and Types section.