I'm fairly new to C++. Can someone help me with a problem I'm stuck on? Below is a data file that has 3 fields in each record. I have to read the fields into a structure one record at a time. Any suggestions would be greatly appreciated.
amazon.com 9250000 250 uudcus.edu 11075 62570 itmagazine.com 10609500 9075 usaf.org 84500
90500 myspace.net 7500 560
I have to create a screen report with a title, each record listed on a new line, and the following totals:
Total revenue
Total hits
Average revenue
Number of records in the file (this is a counter).
The program should contain these functions:
DisplayTitle
ReadRec
DisplayRec
DisplayTotals
This is what I have so far:
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
void DisplayTitle();
struct webRec
{
string websiteUrl;
int hits;
double revenue;
};
webRec ReadRec(ifstream&);
void DisplayRec(webRec);
int main()
{
webRec record;
ifstream inFile;
inFile.open("c:\\websiteHits.txt");
if (inFile.fail ())
{
cout << "Input file opening failed.\n\n";
exit(1);
}
while(! inFile.eof())
{
record = ReadRec(inFile);
DisplayRec(record);
}
inFile.close();
system("pause");
return 0;
}
Help is needed.
Thanks