0

私の出力は $ に整列していません

すべての cout で cout << left << setw(1) を試しました

#include <iostream>
#include <ios>
#include <iomanip>
using namespace std;

int main() {
    // insert code here...

    float RENT_OR_MORTGAGE;
    float UTILITIES;
    float PHONE;
    float CABLE;
    // H stands for housing
    float TOTAL_MONTHLY_HOUSING_COSTS;
    float TOTAL_ANNUAL_HOUSEING_COSTS;
    char dollars = '$';

    cout << "Enter your monthly costs for the following: " << endl << endl;

    cout << "Rent or Mortgage: ";
    cin >> dollars >> RENT_OR_MORTGAGE;

    cout << "Utilities: " << setw(10) << left;
    cin  >> dollars >> UTILITIES;

    cout << "Phone(s): " << setw(10) << left;
    cin  >> dollars >> PHONE;

    cout << "Cable: " << setw(10) << left;
    cin  >> dollars >> CABLE;

    TOTAL_MONTHLY_HOUSING_COSTS = RENT_OR_MORTGAGE + UTILITIES + PHONE + CABLE;
    TOTAL_ANNUAL_HOUSEING_COSTS = (RENT_OR_MORTGAGE + UTILITIES + PHONE + CABLE) * 12;

    cout << fixed << setprecision(2) << setw(dollars) << left << "Total monthly housing costs: "  << dollars << TOTAL_MONTHLY_HOUSING_COSTS << endl << setw(dollars) << left << "Total annual housing costs: " << dollars << TOTAL_ANNUAL_HOUSEING_COSTS << endl;

    return 0;




 I want an output of 


Enter your monthly costs for the following:

Rent or mortgage: $1348
Utilities: $215
Phone(s):  $99
Cable:     $69

Total monthly housing costs: $ 1731.00
Total annual housing costs:  $20772.00

my output is 


Enter your monthly costs for the following: 

Rent or Mortgage: $1348
Utilities: $512
Phone(s):  $99
Cable:     $69
Total monthly housing costs:        $2028.00
Total annual housing costs:         $24336.00

$ に揃えたい。setw() を試してみましたが、内部の数字を変更し続けましたが、何も変わりませんでした。#include がありますが、変更はありません。これは、正しい結果を一致させようとしている小さなプロジェクトです。アドバイスをいただければ幸いです、読んでいただければ幸いです。

4

1 に答える 1