First let me thank you for taking the time to read this.
I've been working on this code for a while and I can't seem to get it to run. Basically what I have to do is take in data from a file then output the data in a report on screen. It sounds simple but unfortunately I can't seem to grasp the concept. All I am asking for is some guidance, not for someone to just fix the code as that would be cheating. I refuse to cheat and I'm just really stuck. Maybe just point me in the right direction or tell me if I'm not even close?
The .dat file gives this information:
amazon.com 820000 350 fhsaswd.gov 22040 40020 pcmagazine.com 760900 500 umbc.edu 89075 36000 mdspc.org 4500 230
And here's my buggy code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct Record
{
string WebsiteURL;
int Hits;
double Revenue;
};
void DisplayTitle();
double GetData(Record, ifstream & infile);
void DisplayTotals(Record, ifstream & infile);
int main()
{
DisplayTitle();
ifstream infile;
infile.open("websiteHits.dat");
if (infile.fail())
{
cout << "Input file opening failed.\n\n";
exit(1);
}
while(!infile.eof())
{
GetData(Record, infile);
}
DisplayTotals(Record, infile);
infile.close();
system("pause");
return 0;
}
void DisplayTitle()
{
cout << "Title";
}
double GetData(Record, ifstream & infile)
{
infile.get(Record.WebsiteURL, ' ');
infile.get(Record.Hits, ' ');
infile.get(Record.Revenue);
}
void DisplayTotals(Record, ifstream & infile)
{
cout << "Website URL: Total Hits: Revenue: " << Record.WebsiteURL << "/n"
<< Record.Hits << "/n"
<< Record.Revenue << endl;
}
Once again thank you for taking the time to read this. All help is appreciated.
Oh and if you need any additional information just ask.