我的输出未与 $ 对齐
我在我所有的 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 但没有变化。这是一个小项目,我试图匹配正确的结果。请分享一些建议,我期待着阅读它。