ilovenyc
ilovenyc

Reputation: 3

My program is not outputting anything from the file :/

I am doing the following exercise:

enter image description here

My code:

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

using namespace std;

int main()
{
    ifstream inFile;
    ofstream outFile;

    double currentSalary, increaseRate, updatedSalary;
    string firstName, lastName;

    inFile.open ("Data.txt");
    outFile.open("Output.dat");
    outFile << fixed << showpoint << setprecision(2);
    inFile >> lastName >> firstName;
    inFile >> currentSalary >> increaseRate;
    updatedSalary = currentSalary * (1 + increaseRate / 100);
    outFile << firstName << " " << lastName<< " " << updatedSalary << endl;
    inFile >> lastName >> firstName;
    inFile >> currentSalary >> increaseRate;
    updatedSalary = currentSalary * (1 + increaseRate / 100);

    outFile << firstName << " " << lastName<< " " << updatedSalary << endl;
    inFile >> lastName >> firstName;
    inFile >> currentSalary >> increaseRate;
    updatedSalary = currentSalary * (1 + increaseRate / 100);
    outFile << firstName << " " << lastName<< " " << updatedSalary << endl;

    system("PAUSE");
    return 0;
}

But when I debug it with MS VS.. it just says "press any key to continue..."

Where do I add the Data.txt file?

Upvotes: 0

Views: 170

Answers (2)

paxdiablo
paxdiablo

Reputation: 881463

Well, given that you don't output anything to the screen, I'm not at all surprised that's all you see.

If I were you, I'd have a look at the Output.dat file to see if it's writing anything.

If you're seeing nothing in that file, then it's probably because you don't have your Data.txt file in the directory where you're running. With VS, this is usually under the bin or debug directory somewhere inside your solution directory.

You can find out which directory that is by putting system("cd"); at the start of your code and running it.

Upvotes: 3

coelhudo
coelhudo

Reputation: 5080

You have to put the Data.txt at the same directory where you will execute the binary file or put the absolute path of Data.txt, like inFile.open ("C:\Documents\Data.txt"), otherwise will never be found.

Upvotes: 1

Related Questions