I need help with a program using selection sort

So, I figured I had my code working. However, when ran its not displaying the pitchers names from my file. it displays the ERA in ascending order, just not the pitchers names. Heres my code:

#include <iomanip>
#include <fstream>
#include <string.h>
using namespace std;

void SelectionSort(char pitchers[][30], int pitcherNum, float IP[], float ERA[]);

void swapPitchers(char pitchers[][30], int Min, int passNum, int pitcherNum);

int main()
{

ifstream myFile;
myFile.open("file.txt");
char pitchers[50][30];
float ERA[50];
float Innings;
int EarnedRuns;
float IP[50];
int ER[50];
int pitcherNum=0;
int v;
int k;


for (k=0; k<50; k++)
{

IP[k]=0;
ER[k]=0;

}

while (!myFile.eof()) //start outer loop
{
myFile.get(pitchers[v],30);

myFile>>ws; // extract whitespace to move to next line

while(myFile.peek()>='0' && myFile.peek() <='9') //start inner loop
{
myFile>>Innings>>EarnedRuns>>ws;

SelectionSort(pitchers, pitcherNum, IP, ERA);

IP[pitcherNum]+=Innings;

ER[pitcherNum]+=EarnedRuns;

} //end inner loop

ERA[pitcherNum]=ER[pitcherNum]*9/IP[pitcherNum];

pitcherNum++;

SelectionSort(pitchers, pitcherNum, IP, ERA);




} //end main while..


for(v=0; v<pitcherNum; v++)
{


cout<<pitchers[v]<<" ";

cout<<fixed<<setprecision(2);

cout<<IP[v]<<" ";

cout<<ERA[v]<<endl;

}


}// start of sorting

void SelectionSort(char pitchers[][30], int pitcherNum, float IP[], float ERA[])
{
int Min;
int passNum;


for (passNum=0; passNum<pitcherNum-1; passNum++)
{
Min=passNum;

for (int k=passNum+1; k<pitcherNum; k++)
{

if(ERA[k]<ERA[Min])

Min=k;

}



swap(ERA[Min], ERA[passNum]);

swap(IP[Min], IP[passNum]);

swapPitchers(pitchers, Min, passNum, pitcherNum);



}
}


void swapPitchers(char pitchers[][30], int Min, int passNum, int pitcherNum)
{
char temp[30];

for (int k=passNum+1; k<pitcherNum; k++)
{
strcpy(temp, pitchers[Min]);
strcpy(pitchers[Min], pitchers[passNum]);
strcpy(pitchers[passNum], temp);
}

}





This only prints out
"∞vpbè 25.67 1.75
 20.34 3.10
25.51 5.64".
There should be names before the numeric values. They should be where the gibberish characters are.

Thanks,
EM.

The gibberish probably comes from myFile.get(pitchers[v],30);
What value do you think does v have?

BTW Is this homework where you have to use all this old C stuff?
Topic archived. No new replies allowed.