Program will not read the data file

I have to create a program that will read a data file and output the data into a file. The program is not reading the information from the data file. The data file is written in note pad file named inData.txt. Here is the program and the data in the file. Please help me fix this.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main ()
{
ifstream inFile;
ofstream outFile;

double salary, bonus, taxes;
double mile, hour;
double averageSpeed;
int sold;
double cost;
double amount;
double average;

string firstName;
string lastName;
string department;

inFile.open("inData.txt");
outFile.open("outData.txt");

outFile << fixed << showpoint;
outFile << setprecision (2);

inFile >> firstName >> lastName >> department;
outFile << "Name: " << firstName << " " << lastName
<< "Department: " << department << endl;

inFile >> salary >> bonus >> taxes;
outFile << "Monthly Gross Salary: " << "$" << salary
<< "," << " " << "MonthlyBonus: " << bonus
<< "%," << " " << "Taxes: " << taxes << "%"
<< endl << endl;


inFile >> mile >> hour;
outFile << "Distance Traveled: " << mile << " miles,"
<< " " << "Traveling Time: " << hour << endl;

average = hour / mile;

outFile << "Average Speed: " << average << " miles per hour"
<< endl << endl;

inFile >> sold >> cost;
outFile << "Number of Coffee Cups Sold: " << sold << ","
<< "Cost: $" << cost << " " << "per cup" << endl;

amount = sold * cost;

outFile << "Sales Amount: " << "$" << amount << endl;

inFile.close();
outFile.close();

return 0;
}



Data File info

Giselle Robinson Accounting
5600 5 30
450 9
75 1.5
Last edited on
Looks like you're outputting to your outfile, and inputting from your infile. If your original statement is true, you want your data to be stored in infile.txt, not outfile.txt.
> The data file is written in note pad file named outData.txt.
¿your _input_ file is called `outData.txt'?


> inFile.open("inData.txt");
you said that you will open `inData.txt'.
Make sure that the name is correct and that the file is in the working directory.
Topic archived. No new replies allowed.