a program needs to calculate and display the total of the weekly payroll amounts stored in the data file
the data file has the following info :
25000.89
35600.50
45678.99
67000.89
now the only problem is that when I run the program it does not give me the correct answer which is 173280.94, what am I doing wrong??
and here is the program that I have so far:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
//declare variables
float total = 0.0;
int counter = 0;
//open file
ifstream inFile;
inFile.open ("T13ConE07.dat", ios::in);
//determine if the file was opened
if (inFile.is_open())
{
//declare varables
float payroll = 0;
//read and display records
while (!inFile.eof())
{
inFile >> payroll;
inFile.ignore();
counter = counter + 1;
//display records
cout << fixed;
cout.precision(2);
cout << payroll <<endl;
}//end while
//close file
//calculate total
total = payroll;
inFile.close();
cout << "Total is: " << total <<endl;
}
else
cout << "File could not be opened. " <<endl;
//end if
return 0;
}//end of main function
the data file has the following info :
25000.89
35600.50
45678.99
67000.89
now the only problem is that when I run the program it does not give me the correct answer which is 173280.94, what am I doing wrong??
and here is the program that I have so far:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
//declare variables
float total = 0.0;
int counter = 0;
//open file
ifstream inFile;
inFile.open ("T13ConE07.dat", ios::in);
//determine if the file was opened
if (inFile.is_open())
{
//declare varables
float payroll = 0;
//read and display records
while (!inFile.eof())
{
inFile >> payroll;
inFile.ignore();
counter = counter + 1;
//display records
cout << fixed;
cout.precision(2);
cout << payroll <<endl;
}//end while
//close file
//calculate total
total = payroll;
inFile.close();
cout << "Total is: " << total <<endl;
}
else
cout << "File could not be opened. " <<endl;
//end if
return 0;
}//end of main function