My program is supposed to get random numbers and put them in the array. Then it's supposed to find lowest, highest, sum, and average. Everything works except the lowest function. Any help please! EDIT: posted whole program
int main()
{
int nums[SIZE] = { 0 };
int smallest;
int highest;
int sum;
double avg;
putNums(nums);
getNums(nums, SIZE);
getLowest(nums, SIZE, smallest);
getHighest(nums, SIZE, highest);
getSum(nums, SIZE, sum);
getAvg(nums, SIZE, sum, avg);
cout << "Smallest number of array: " << nums[smallest] << endl;
cout << " Highest number of array: " << nums[highest] << endl;
cout << "Sum of the array: " << sum << endl;
cout << "Average of the array: " << setprecision(2) << fixed << showpoint << avg << endl;
}
void putNums(int nums[])
{
ofstream outFil; // output file object
string filNam; // output file name
srand(static_cast<unsigned int>(time(0))); // seed random number generator
int num; // random number to be generated
int cnt = 1; // count of random numbers
cout << "To generates a file of " << SIZE << " random numbers\n";
cout << " enter your output file name: "; // "nums.txt"
cin >> filNam;
outFil.open(filNam.c_str());
if (outFil) {
for (int k = 0; k < SIZE; ++k) { // generate and write numbers
num = MIN + rand() % MAX; // generate random number
cout << cnt << ". " << num << endl;
outFil << num << endl;
nums[cnt] = num;
++cnt; // increment count of numbers
} // endfor
}
else {
cout << "Open error on file " << filNam << endl;
exit(1);
} // endif
outFil.close(); // close the file
cout << "\n -- Done - file closed! --\n\n";
}
void getNums(int nums[], int SIZE)
{
cout << "Your " << SIZE << " number(s) are listed: \n";
for (int cnt = 1; cnt <= SIZE; cnt++){
cout << nums[cnt] << endl;
}
}
int getLowest(int nums[], int size, int & smallest)
{
smallest = 0;
int lowest = nums[0];
for (int cnt = 0; cnt <= SIZE; ++cnt){
if (nums[cnt] < lowest){
lowest = nums[cnt];
smallest = cnt;
}
}
return smallest;
}
int getHighest(int nums[], int SIZE, int & highest)
{
highest = 0;
int largest = nums[0];
for (int cnt = 0; cnt < SIZE; ++cnt){
if (nums[cnt] > largest){
largest = nums[cnt];
highest = cnt;
}
}
return highest;
}
int getSum(int nums[], int size, int & sum)
{
sum = 0;
for (int cnt = 0; cnt < SIZE; ++cnt){
sum += (nums[cnt]);
}
return sum;
}
double getAvg(int nums[], int size, int sum, double & avg)
{
avg = 0;
avg = static_cast<double>(sum) / SIZE;
return avg;
}
smallest = cnt + 1?std::min_element.