Hey guys, pretty confused about what a "pass-by-reference" function is and does. No one will put it into simple English for me and Google has become my worst enemy on the topic.
What the Program has to do is convert the five-numbers of a zip code (for example: "64110") into words ("Siz Four One One 0"). It has to display the First and last name of the resident, their street, city, state, and then the zipcode. HERE IS THE KICKER: It must all be read from an input file! Below is my coding so far. It will not compile in Visual Studio (2008), and as you can tell from it being cut-off, I don't know what to do:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
bool checkFileInput (ifstream &fin);
bool checkFileOutput (ofstream &fout);
int changeZipcode (string firstName, string lastName, int houseNumber, int street, int city, int state, int zipcode, int zipChange, string fullzipcode);
int main()
{
ifstream fin("program5.txt");
ofstream fout("output5.txt");
fin.open("program5.txt");
fout.open("output5.txt");
if(! checkFileInput(fin))
{
exit(2);
}
if(! checkFileOutput(fout))
{
exit(3);
}
cout << "Go check the output file\n" << endl;
fin.close();
fout.close();
}
int changeZipcode (int zipcode, int fullzipcode)
{
return 0;
}
bool checkFileInput (ifstream &fin)
{
if(fin.good())
{
return true;
}
else
{
cerr << "Unable to Open file\n";
return false;
}
}
bool checkFileOutput (ofstream &fout)
{
if(fout.good())
{
return true;
}
else
{
cerr << "Unable to write to Output file\n";
return false;
}
}
int changeZipcode (string firstName, string lastName, int houseNumber, int street, int city, int state, int zipcode, int zipChange string fullzipcode)
{
while (fin >> firstName >> lastName >> houseNumber >> street >> city >> state >> zipcode)
{
if(zipcode>=10000)
{
zipChange=(zipcode/10000)
}
if(zipChange=1)
{
zipChange = one;
}
if(zipChange = 2)
{
zipChange = two;
}
if(zipChange = 3)
{
zipChange = 3
}
if(zipChange=4)
{
zipChange = four;
}
if(zipChange=four)
{
zipChange = four;
}
if(zipChange=5)
{
zipChange = five;
}
}
As you can see, the number one problem I am having is using a "pass-by-reference" function to change the zipcode. I don't even know what it does or how to use it! But I have to use it. Because I thought that at least I'd be getting somewhere, I went ahead and put the information into the int function "changeZipcode". But, now I'm having trouble figuring out how to get the program to read each individual number and then convert it into words! Can anyone help me?