OS: Win 2K Compiler MSVC++ 6.0
This program was supposed to work. I got the example from a C++ book, all I did is changing the wording in the char array the program keep aborting with errors I simply cannot fix. And all those warnings what do they mean? Anyway here is the program and the errors.
=============================================
/* This program uses the selection sort algorithm to sort an
array in ascending order.
this will sort the names and their corresponding values
Error messages:
-------------Configuration: selectSortVendorPrices - Win32 Debug--------------------
Compiling...
selectSortVendorPrices.cpp
C:\Desktop\selectSortVendorPrices.cpp(14) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
C:\Desktop\selectSortVendorPrices.cpp(14) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
C:\Desktop\selectSortVendorPrices.cpp(15) : error C2117: 'F_Coop' : array bounds overflow
C:\Desktop\selectSortVendorPrices.cpp(15) : error C2078: too many initializers
C:\Desktop\selectSortVendorPrices.cpp(37) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
C:\Desktop\selectSortVendorPrices.cpp(42) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
C:\Desktop\selectSortVendorPrices.cpp(49) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
Error executing cl.exe.
selectSortVendorPrices.obj - 2 error(s), 5 warning(s)
*/
---- - - - - - - - -
My codes:
#include <iostream.h>
// Function prototypes
void selectionSort(float values[], char corr[], int);
void showArray(float values[], char corr[], int);
void main(void)
{
float values[3] = {1.50, 1.79, 2.29};
char corr[3] = {"HP", "FCoop", "YN"}; // corresponding array
cout << "The unsorted values are\n";
showArray(values, corr, 3);
selectionSort(values, corr, 3);
cout << "The sorted values are\n";
showArray(values, corr, 3);
}
//************************************************** ************
// Definition of function selectionSort. *
// This function performs an ascending order selection sort on *
// array. elems is the number of elements in the array. *
//************************************************** ************
void selectionSort(float values[], char corres[], int elems)
{
int startScan, minIndex, minValue, minimum;
for (startScan = 0; startScan < (elems - 1); startScan++)
{
minIndex = startScan;
minValue = values[startScan];
for(int index = startScan + 1; index < elems; index++)
{
if (values[index] < minValue)
{
minValue = values[index];
minimum = corres[index];
minIndex = index;
}
}
values[minIndex] = values[startScan];
corres[minIndex] = corres[startScan];
values[startScan] = minValue;
corres[startScan] = minimum;
}
}
//************************************************** ************
// Definition of function showArray. *
// This function displays the contents of array. elems is the *
// number of elements. *
//************************************************** ************
void showArray(float values[], char corres[], int elems)
{
for (int count = 0; count < elems; count++)
cout << values[count] << " " " - " << corres[count] << endl;
cout << endl;
}