In case the guys who helped me with a "pass-by-reference" function didn't see it, thank you for your help!
I've only got one problem right now and thats that my program will not send data to an output file. Here's the code:
bool checkInputFile(ifstream &fin); // checks the file input
void changezipcode(int zipcode, string &newzipcode); // this is the function that processes the data from numbers to words
int main()
{
ifstream fin;
ofstream fout;
string firstName;
string lastName;
int houseNumber, city, street, state;
int zipcode1;
int zipcode;
string newzipcode;
fin.open("program5.txt");
fout.open("output5.txt");
if (! checkInputFile(fin))
{
exit(2);
}
if(fout.fail())
{
cerr << "Unable to open output file\n";
exit(3);
}
while(fin >> firstName >> lastName >> houseNumber >> street >> city >> state >> zipcode1)
{
zipcode1 = zipcode;
changezipcode(zipcode, newzipcode); // Function Call
fout << setw(10) << firstName << setw(10) << lastName << setw(10) << street << setw(10) << city << setw(10) << state << setw(10) << zipcode << endl;
}
cout << "Please view the Outputfile: output5.txt\n"; // Prompts user to see the output
fin.close();
fout.close();
return 0;
}
bool checkInputFile(ifstream &fin) // Checks input
{
if(fin.good())
{
return true;
}
else
{
cerr << "Unable to open input file\n";
return false;
}
}
void changezipcode(int zipcode, string& newzipcode) // The function
{
int div=10000;
string parse="";
int temp;
while(div>0)
{
temp=(zipcode/div);
switch (temp)
{
case '0': parse+="zero"; break;
case '1': parse+="one"; break;
case '2': parse+="two"; break;
case '3': parse+="three"; break;
case '4': parse+="four"; break;
case '5': parse+="five"; break;
case '6': parse+="six"; break;
case '7': parse+="seven"; break;
case '8': parse+="eight"; break;
case '9': parse+="nine"; break;
}
zipcode=zipcode-(temp*div);
div=div/10;
}
newzipcode=parse;
return;
}
It all LOOKS good. Upon comparing it to several other program though, I can't figure out why its not taking the information and placing it into an output file. Can anyone tell me why? Also, is there anything wrong with my function call?