data.txt
contains the following information: firstName
, lastName
, salary
, increment
.
James Chong 5000 3
Peter Sun 1000 5
Leon Tan 9500 2
I want to read data.txt
, make the necessary calculations, and store the output of 3 variables in anewData.txt
:
firstName
, lastName
, updatedSalary
(salary
*percentageIncrement
)
I only managed to proceed to reading and display information in data
.
Below is my code:
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
string filename = "data.txt";
ifstream infile;
infile.open(filename);
//if file cannot open, exit program
if (!infile.is_open()){
exit(EXIT_FAILURE);
}
string word;
infile >> word;
while(infile.good()){
cout << word << " ";
infile >> word;
}
system("pause");
return 0;
}
May I know are there any references that I can make use of? Thank you