私はC++に非常に慣れていないので、doubleとして宣言された変数をtxtファイルにどのように出力/書き込みするのか疑問に思っています。fstreamを使用して文字列を出力する方法は知っていますが、他のものを送信する方法がわかりません。文字列以外はテキストファイルに送信できないと思い始めていますが、それは正しいですか?もしそうなら、変数に格納されている情報を文字列変数にどのように変換しますか?
これが私がこの概念を実装しようとしている私のコードです、それはかなり単純です:
int main()
{
double invoiceAmt = 3800.00;
double apr = 18.5; //percentage
//compute cash discount
double discountRate = 3.0; //percentage
double discountAmt;
discountAmt = invoiceAmt * discountRate/100;
//compute amount due in 10 days
double amtDueIn10;
amtDueIn10 = invoiceAmt - discountAmt;
//Compute Interest on the loan of amount (with discount)for 20 days
double LoanInt;
LoanInt = amtDueIn10 * (apr /360/100) * 20;
//Compute amount due in 20 days at 18.5%.
double amtDueIn20;
amtDueIn20 = invoiceAmt * (1 + (apr /360/100) * 20);
return 0;
}
だから私がやろうとしているのは、それらの変数を使ってテキストファイルに出力することです。また、このソースコードに使用する必要のあるインクルードについて教えてください。他の方法でもコードを改善する方法について、遠慮なく提案してください。
前もって感謝します。