for the life of me i cannot figure out why this wont just read in and output correctly. when i cout it, it wont get the third number and i end up with:
2800000
0
24
input is 2800000.00 24 8.40
#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
usingnamespace std;
int main()
{
ifstream inData;
ofstream outData;
string infileName;
string outfileName;
long intBalance;
float annInterest;
float numOfpayments;
inData.open("zon.txt");
/*cout << "Enter the input data file name:" << endl;
cin >> infileName;
inData.open(infileName.c_str());
// make it a loop error message so user doesnt have to restart program. Annoying
if(!inData)
{
cout << "Can't open the input file. Program is stopping" << endl;
return 1;
}
*/
/*cout << "Enter the name of the file where you want the results stored: " << endl;
cin >> outfileName;
outData.open(outfileName.c_str());
*/
inData >> intBalance >>annInterest >>numOfpayments;
return 0;
}
It's probably because you declared intBalance to be an integer. So, when it reads the file, it stops at the point. annInterest reads the 00, and then numof payments reads the 24. Try changing intBalance to a float and annInterest to the integer.