値を渡して別の変数に代入すると、それらを一緒に追加することはできません。両方の合計をファイルに出力しますが、一緒に出力することはできません。誰も私の間違いを指摘できますか?C++は渡された値を追加しません
void financialReport(int price)
{
ofstream financial_log("financial.txt", ios::app);
int total = 0;
total += price;
int test = total++;
financial_log << "Total: " << test;
financial_log.close();
}
cout << "Destination: ";
cin >> destination;
cout << "Price agreed: ";
cin >> price;
financialReport(price);
これは私が私のテキストファイルに出力されます取得:
Total4Total5
また、何らかの理由で、合計と価格の間にスペースはありません。
よくフォーマットされた入力、期待される出力、入手したものを提供してください。 –
だから、入れてlongにだが、ここで予想される、それ のアイデアです: 先:「ブラブラ」 価格:3 先:「何とか2」 価格:4 私は出力を期待していするファイル: 合計:7 しかし、私が得ることTotal4Total3 – Josh
私は、最小完全、かつ検証可能な例を提供してくれるわけ ある - 'financial_logとhttp://stackoverflow.com/help/mcve –