Basically I have a program that is designed to read a file that contains a first & last name a integer, and a double.
What happens is the double contains a comma, which the program reads as a white space. At that point all the data gets shifted, and i end up with char in a integer handler. You can guess what happens from there.
int main()
{
char quest, pathi[81] = "../employee.dat", patho[81] ="../managers.dat", name_first[20], name_last[20];
int dep;
double wage, wage1;
ifstream inFile;
ofstream outFile;
cout <<"\nThe current path to input file is " <<pathi<<endl;
cout <<"Do you wish to use the expected file path for this Program? Y, or N \n";
cin >>quest;
if ((quest == 'n') || (quest == 'N'))
{
cout<<"Type in the address, and name of file you wish to use.\n";
cin >> pathi;
}
quest = 'y';
cout << "\nBegin editing files. \n";
cout <<"Openning "<<pathi<<endl;
inFile.open(pathi); //start file, and location relative to program
if(inFile.fail())
{
cout<<"Input file failed to open.\n";
exit(1);
}
cout <<"The current path to output file is " <<patho<<endl;
cout <<"Do you wish to use the expected file path for this Program? Y, or N \n";
cin >>quest;
if ((quest == 'n') || (quest == 'N'))
{
cout<<"Type in the address, and name of file you wish to use.\n";
cin >> patho;
}
cout<<"The output is going to: " <<patho<<endl;
/* outFile.open(patho, ios::app); //creates new blank file for export
if (outFile.fail())
{
cout<< "Output file failed to open";
exit(2); //leaves program # is the error code
} */
int pro= 0;
outFile.setf(ios::fixed);
outFile.setf(ios::showpoint);
outFile.precision(2);
while(!inFile.eof())
{
inFile >> name_first >> name_last >> dep >> wage; //this is where is goes wrong
cout << name_last << ", " << name_first << " "<< wage<<endl;
pro++;
if (pro>20)
break;
}
inFile.close();
//outFile.close();
cout<< "End of editing files. \n";
return 0;
}
[input]Sue Leon 4 55,000.00
Robert Wise 3 42,500.00
Sam Woo 1 47,000.00
Nathan White 3 32,500.00
Suzan Head 2 52,000.00
Henry Williams 4 45,500.00
Christine Mint 1 68,400.00
Kim Leeds 4 29,000.00
Elton Sue 3 39,600.00
Ozzie Lynch 2 41,000.00
Ken Latch 2 45,700.00
Tom Sawyer 4 49,300.00
Tommy High 3 44,000.00
Ann Silver 3 54,000.00
Tony Hope 4 41,000.00
Tammy Lee 4 29,500.00
Liz McCabe 1 59,000.00
Andy Wong 3 70,700.00
Tony Hope 1 49,200.00
Bright Gold 2 44,100.00[/input]