#include<iostream>
#include<fstream>
int main(){
using namespace std;
char automobile[50];
int year;
double a_price,d_price;
ofstream outFile; // 產生輸出物件,簡單來說就是 cout 區段的複製。(將 cout 取代為 outFile )
outFile.open("carinfo.txt"); // open() 函數與檔案建立關聯。
cout << "Enter the make and model of automobile: ";
cin.getline(automobile, 50);
cout << "Enter the model year: ";
cin >> year;
cout << "Enter the original asking price: ";
cin >> a_price;
d_price = 0.913* a_price;
//
cout.precision(2);
cout.setf(ios_base::showpoint);
cout << fixed; // 說明請見連結 http://it-easy.tw/cout-float/
cout << "Make and model: "<< automobile << endl;
cout << "Was asking $" << a_price << endl;
cout << "Now asking $" << d_price << endl;
//
outFile << fixed;
outFile.precision(2);
outFile.setf(ios_base::showpoint);
outFile << "Make and model: " << automobile << endl;
outFile << "Year: " << year << endl;
cout << "Was asking $" << a_price << endl;
cout << "Now asking $" << d_price << endl;
outFile.close(); // 程式完成檔案的使用後,關閉連結。
system("pause");
return 0;
}
沒有留言:
張貼留言