【发布时间】:2016-11-11 23:43:06
【问题描述】:
大家好,我刚开始使用数组。
请有人对这个话题有所了解。这是我创造的,我认为它是有道理的,但我一定错过了一些东西。 我收到调试错误运行时检查失败 #2 - S
错误类型如下:Debug Error Run-Time Check Failure #2 - S
#include<iostream>
#include<iomanip>
#include <climits>
//Prototypes:
int lowestAmount(int[]);
int highestAmount(int[]);
using namespace std;
int main() {
const int AMOUNT = 9;
int values[AMOUNT];
int lowest, highest;
cout << "Please Insert 10 Numbers of your Choice: ";
cin >> values[0] >> values[1] >> values[2] >> values[3] >>
values[4] >> values[5] >> values[6] >> values[7] >>
values[8] >> values[9];
cout << endl;
lowest = lowestAmount(values);
highest = highestAmount(values);
cout << "/tThe Lowest out of all of them is: " << lowest <<
endl;
cout << "/tThe Highest out of all of them is: " << highest << endl ;
return 0;
}
int lowestAmount(int val[]) {
int lowest = INT_MAX;
int count = 10;
for (int i = 0; i < count; i++) {
if (val[i] < lowest)
lowest = val[i];
}
return lowest;
}
int highestAmount(int val[]) {
int highest = INT_MIN;
int count = 10;
for (int i = 0; i < count; i++) {
if (val[i] > highest)
highest = val[i];
}
return highest;
}
代码有点工作,但不是一直正确,我不知道我做错了什么?我虽然我的逻辑是错误的???有人能解释一下吗???
【问题讨论】:
-
嗨!你的代码doesn't work?
-
它,有点,但我得到一个错误说。调试错误运行时检查失败 #2 - S
-
我将两个函数中的 count var 都增加了 1,所以我放了 10 而不是 9,但我仍然得到错误???