我的數據文件包含以下數字錯誤的值在C++閱讀從文件
/*
111
100.00
200.00
50.00
222
200.00
300.00
100
*/
被讀取,但while循環customerNumber之原文100之後,它應該是111,它獲得的該值一切都是錯的。如beginBalance的讀數爲
//-9255963134931783000000000000000000000000.00
和其他一切似乎都讀取相同的值。我只是在瞭解文件,所以任何幫助將不勝感激。
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
int customerNumber;
double beginningBalance, purchase, payments, financeCharge, endingBalance;
ifstream inputFile;
ofstream outputFile;
inputFile.open("BeginningBalance.dat");
cout<<"Cust No | Beginning Bal | Finance Charge | Purchases | Payments | Ending Balance"<<endl;
while (inputFile >> customerNumber);
{
inputFile >> beginningBalance;
inputFile >> purchase;
inputFile >> payments;
financeCharge = beginningBalance * .01;
endingBalance = beginningBalance + purchase + financeCharge - payments;
cout<<setw(5)<<customerNumber<<fixed<<setprecision(2)<<" "<<beginningBalance<<" "<<financeCharge<<" "<<purchase<<" "<<payments<<" "<<endingBalance<<endl;
}
system ("PAUSE");
return 0;
}
您是否嘗試刪除'/ *'和'* /'並查看會發生什麼? – hochl
數據文件中實際是'/ *'還是'* /'? – trojanfoe
不要使用雙打財務數據。 – kan