它一直在说标识符" posi"由于某种原因未定义,搜索它但发现没有相似之处,任何人都可以帮忙吗?代码如下,我不熟悉编程,而不熟悉c ++,请帮助,谢谢。
#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;
}
}
答案 0 :(得分:1)
它说它未定义,因为你从未定义它。在此函数中调用pmax = maximum(max, num, posi);
,您将posi
传递给最大值,但您还没有定义它!您调用maximum
而不是minimum
的错误的原因可能是因为编译器在遇到未定义的引用时停止编译。如果您移除了对maximum
的来电,那么当您尝试cin >> max[i] >> posi[i];
时,它会给您一个错误。如果您删除该行,那么当您致电minimum,
时,它会给您一个错误,依此类推。我建议查看一些基本的C ++教程,these ones非常好。特别是Variables and Types部分。