Input and Output to file - help please
The input file contains whole number values arranged like this:
50000
10250
15250
ect...
Now, I need to read this file, then use each number as an INT type to preform calculations on.
I then need to output the calculated info to an output file along with some added text to explain the calculations.
You can see what I am trying to do from the code below.
My problem is that I need a better way to actually grab the input, and send the output.
Right now the only way I know how to output is to redirect the cout to a file.
The input is semi-functional. It only takes the first number of each line.
Please forgive me if any code is hard to read..I have been trying tons of things to get this to work..so there may be some left over code from previous attempts.
#include <iostream>
#include <fstream>
using namespace std;
#define RaisePercent .025; //.025 = 2.5%
float OldSalary, NewSalary, SalaryIncrease = 0;
float TotalOldSalary, TotalNewSalary, TotalIncrease = 0;
ifstream ins;
ofstream outs;
void Raise(ifstream&, ofstream&);
void GetInput();
////////////////////////////////////////////////////////////////////
int main()
{
cout.rdbuf(outs.rdbuf()); // Redirects cout to file
GetInput();
Raise(ins, outs);
return 0;
}
////////////////////////////////////////////////////////////////////
void GetInput()
{
ins.open("C:\\Documents and Settings\\Arcane\\Desktop\\In.txt");
outs.open("C:\\Documents and Settings\\Arcane\\Desktop\\Out.txt");
}
///////////////////////////////////////////////////////////////////
void Raise(ifstream& ins, ofstream& outs)
{
char input;
while (!ins.get(input) == NULL)
{
ins.ignore(256, '\n');
OldSalary = input - '0'; //Convert CHAR to INT
cout<<"Original Salary $"<<OldSalary<<endl<<endl;
TotalOldSalary = TotalOldSalary + OldSalary;
SalaryIncrease = OldSalary * RaisePercent;
NewSalary = SalaryIncrease + OldSalary;
TotalNewSalary = TotalNewSalary + NewSalary;
TotalIncrease = TotalIncrease + SalaryIncrease;
cout<<"The new Salary is $"<<NewSalary<<endl;
cout<<"This is an increase of $"<<SalaryIncrease<<endl<<endl;
}
cout<<"The total salary was $"<<TotalOldSalary<<endl;
cout<<"The total new salary will be $"<<TotalNewSalary<<endl;
cout<<"This is a total increase of $"<<TotalIncrease<<endl<<endl<<endl;
}
Input File:
50000
20000
15000
60000
Output File:
Original Salary $5
The new Salary is $5.125
This is an increase of $0.125
Original Salary $2
The new Salary is $2.05
This is an increase of $0.05
Original Salary $1
The new Salary is $1.025
This is an increase of $0.025
Original Salary $6
The new Salary is $6.15
This is an increase of $0.15
The total salary was $14
The total new salary will be $14.35
This is a total increase of $0.35
Thanks in advance!

