Мой вывод не выравнивается по $
Я пробовал cout << left << setw (1) на всех моих cout </p>
#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, но без изменений.Это небольшой проект, в котором я пытаюсь найти правильный результат.Пожалуйста, поделитесь советом, я с нетерпением жду его чтения.