I do not know why when I compile it, on why does the last cylinder file print out multiple times int tags1 and tags2. I bolded them so you would see what I am talking about. Could someone please help me out?
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
// function prototypes
void tagReader ( ifstream& inFile, int&count);
void getEmployee ( string& who, double& rate, int &hours );
double paycheck (int hours, double rate);
void repeater ( string word, int num);
bool valid (int val);
void header ();
//=========================================================
int main()
{
int count = 0;
ifstream inFile;
string cylinder, serial;
double num1, num2;
double counter;
//----------------------------------------
// Call function tagReader with tags1.txt
inFile.open("tags1.txt");
if (!inFile)
{
cout << "\n\nError! - Invalid file name! (1)\n\n";
system ("pause");
return 1;
}
inFile >> cylinder;
while (inFile)
{
inFile>> serial;
inFile >> num1;
inFile >> num2;
cout << fixed << showpoint << setprecision(2);
cout <<"Cylinder: " << cylinder << " " << serial << " " << num1 << " " << num2 << endl << endl;
count = 1;
counter++;
while (count < num1)
{ inFile >> cylinder ;
inFile >> serial;
inFile >> num1;
inFile >> num2;
cout << "\nCylinder: " << cylinder << " " << serial << " " << num1 << " " << num2 << endl << endl;
count++;
}
}
cout <<"Results from tags1.txt :\n";
tagReader ( inFile, count);
cout << "File tags1.txt had " << count << " data items. \n\n";
inFile.close ();
//----------------------------------------
// Call function tagReader with tags2.txt
inFile.clear ();
inFile.open("tags2.txt");
if (!inFile)
{
cout << "\n\nERROR! Invalid file name! (2)\n\n";
system ("pause");
return 1;
}
inFile >> cylinder;
while (inFile)
{
inFile>> serial;
inFile >> num1;
inFile >> num2;
cout << fixed << showpoint << setprecision(2);
cout <<"Cylinder: " << cylinder << " " << serial << " " << num1 << " " << num2 << endl << endl;
count = 1;
counter++;
while (count < num1)
{ inFile >> cylinder ;
inFile >> serial;
inFile >> num1;
inFile >> num2;
cout << "\nCylinder: " << cylinder << " " << serial << " " << num1 << " " << num2 << endl << endl;
count++;
}
}
cout <<"Results from tags2.txt :\n";
tagReader ( inFile, count);
cout << "File tags2.txt had " << count << " data items. \n\n";
inFile.close ();
system("pause");
return 0;
}
//**********************************************************************
//Function Name: GetLength
// Prompts the user to input the lenth of a rectangular room
// Returns the int value input by the user
//**********************************************************************
void tagReader (ifstream& inFile, int&count)
{
}
Output:
Cylinder: bsharkdata 1782 12.00 82.90
Cylinder: ftmyersfeb 7150 11.00 32.89
Cylinder: sandiego99 8800 15.20 52.76
Cylinder: turtles666 2180 11.00 14.09
Cylinder: turtles765 4223 11.90 17.10
Cylinder: FredsFish 4145 11.60 42.22
Cylinder: GreatBaReef 8673 10.00 11.40
Cylinder: VaBch77June 1111 13.50 44.00
Cylinder: VaBch77June 1111 13.50 44.00
Cylinder: VaBch77June 1111 13.50 44.00
Cylinder: VaBch77June 1111 13.50 44.00
Cylinder: VaBch77June 1111 13.50 44.00
Cylinder: VaBch77June 1111 13.50 44.00
Cylinder: VaBch77June 1111 13.50 44.00
Results from tags1.txt :
File tags1.txt had 14 data items.
Cylinder: turtles686 2110 14.88 65.19
Cylinder: turtles995 1123 61.60 77.17
Cylinder: UKFishData 4145 99.04 22.98
Cylinder: Gr8BaReef2 8673 19.71 76.12
Cylinder: VaBch78876 1111 69.11 51.10
Cylinder: shark9987 1782 83.40 89.11
Cylinder: florida331 3130 14.01 52.89
Cylinder: florida876 6600 15.20 52.76
Cylinder: flKeys331 4410 64.66 56.22
Cylinder: flKeys877 6630 16.27 52.77
Cylinder: flKeys877 6630 16.27 52.77
Cylinder: flKeys877 6630 16.27 52.77
Cylinder: flKeys877 6630 16.27 52.77
Cylinder: flKeys877 6630 16.27 52.77
Cylinder: flKeys877 6630 16.27 52.77
Cylinder: flKeys877 6630 16.27 52.77
Cylinder: flKeys877 6630 16.27 52.77
Results from tags2.txt :
File tags2.txt had 17 data items.
Press any key to continue . . .