2017-10-20 7 views
0

":"と "$"は、ユーザーが "numShirts"というcinコマンドを使って入力したいずれの入力とも整列しないようにしています。実装されていればそれは一貫しています.10以下であれば、他の入力では割引はありません。C++は、入力がきちんと表示されるように文字を整列させます

http://prntscr.com/gzms3m

[10で実装]![他で実装] http://prntscr.com/gzmsjx

cout << "\n" << endl; 
     cout << fixed; 
     cout << "Thank you for your purchase.\n" << endl; 
     cout << "You bought " << numTShirts << " T-shirts\n" << endl; 

     cout << "Subtotal Total" << setw(5) << ": $ " << right << setprecision(2) << subTotal << "\n" << endl; 
     cout << setprecision(0) << "Discount(" << discountPCT << "%)" << setw(7) << ": $ " << right << showpoint << setprecision(2) << discount << "\n" << endl; 
     cout << setfill('-') << setw(35) << "-\n" << endl; 
     cout << setfill(' '); 
     cout << "Total" << setw(14) << ": $ " << right << showpoint << setprecision(2) << totalPrice << endl; 

enter image description here enter image description here

答えて

1

これは、割引額が可変であるので起こって、それに応じていますスペースが増えます。

例で示すように、割引が1桁の場合、整列が目的の整列になります。そうでない場合は、それが異なります。

discoutnは最大3桁(100%)にすることができるので、2つの出力をフォーマットすることをお勧めします。

1桁の数字は2桁と3桁です。 条件文を使用すると、それぞれを出力に表示できます。

関連する問題