Environment: Desktop, Compiler: MS VC++ 6.0
My program is not putting out the correct result and I don't understand what those warnings means. All I am trying to find is the minimum and maximum value from the array.
Is there MS library that explain those mysterious messages?
Thank you anyone for your help
My codes and results below:
#include <iostream>
using namespace std;
#define num_elems 8
// function prototype
int max_price(int priceList[num_elems], int);
int min_price(int priceList[num_elems], int);
// last upated: Jan. 29, 2002 08:45 p.m - Jan. 30 09:15 p.m
void main()
{
int lowestPrice;
int highestPrice;
// The members of the array
int priceList[num_elems] = {8, 25, 36, 44, 52, 60, 75, 89};
//int minPrice = priceList[0];
//int maxPrice = priceList[0];
//int a = 8;
// Announce the result
lowestPrice = min_price(priceList, num_elems);
cout << "The lowest price in the array is: ";
cout << lowestPrice;
cout << endl;
// Announce the result
//Display the highest price << Maximum << "." << endl;
highestPrice = max_price(priceList, num_elems);
cout << "The highest price in the array is: ";
cout << highestPrice << endl; // num_elems being the # of elements in the array
}// end of main
// =============== ========================= =========== =======
// FUNCTION DEFINITIONS
int max_price(int priceList[], int)
{
//cout << "Finding the Maximum" << endl;
int maxIndex = 0;
int max = priceList[maxIndex]; // assume first element ismax
// now go through the rest of the array
// Compare the members
for ( int i = 1; i < num_elems; ++i)
{
if (priceList[i] > max)
{
max = priceList[i];
maxIndex = i;
}
return maxIndex;
}
}
// find the minimum pice
int min_price(int priceList[], int)
{
int minIndex = 0;
int min = priceList[minIndex]; // assume first element is min
// now go through the rest of the array
// Compare the members
for (int i = 1; i < num_elems; ++i)
{
if (priceList[i] < min)
{
min = priceList[i];
minIndex = i;
}
return minIndex;
}
}
/*
error list & warnings:
-----------Configuration: find_min_max - Win32 Debug------------
Compiling...
find_min_max.cpp
H:\ject\find_min_max.cpp(60) : warning C4715: 'max_price' : not all control paths return a value
H:\ject\find_min_max.cpp(78) : warning C4715: 'min_price' : not all control paths return a value
find_min_max.obj - 0 error(s), 2 warning(s)
// Result of test
The lowest price in the array is: 0 <---WRONG RESULT
The highest price in the array is: 1 <---WRONG RESULT
Press any key to continue
*/