在右侧显示输出
Displaying output to the right
所以我对编程和C++很陌生。这个简单的程序是我的第二个程序,我需要一点帮助。下面是我的代码,后跟我得到的输出以及我希望它的样子。如果有人能指出我正确的方向,或者让我知道如何改变这一点,我们将不胜感激。
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
double propValue, //Property Value
assessment, //Assessment
srAssessment, //Sr Assessment
taxRate, //Tax rate
annualPropTax, //Annual Property tax
quarterlyTax; //Quarterly Tax
string name;
const double EXEMPT = 5000, //shows the total after exemption
QUARTER = 4, //represents the amount of quarters in a year
TAXPERHUNDRED = 0.01, //represents tax rate for every $100
SIXTYPERCENT = 0.6; //Represents the tax based on 60% of original value
//Gets name from user
cout << "Please enter your full name: ";
getline(cin, name);
//gets property value from user
cout << "Enter the actual value of the property: ";
cin >> propValue;
//Gets tax rate
cout << "Enter the tax rate for each $100 of assessed value: ";
cin >> taxRate;
cout << endl << endl;
//Calculates assessment
assessment = propValue * SIXTYPERCENT;
//Calculates Sr. Assessment
srAssessment = assessment - EXEMPT;
//Calculates annual property tax
annualPropTax = srAssessment * taxRate * TAXPERHUNDRED;
//Calculates Quarterly tax
quarterlyTax = annualPropTax / QUARTER;
//Displays owners name
cout << "Property owner's name: " << name << endl;
cout << endl;
cout << setprecision(2) << fixed;
//Displays Assesment
cout << "Assessment: " << setw(18) << "$ " << srAssessment << endl;
//Displays Annual Property tax
cout << "Annual Property Tax" << setw(11) << "$ " << std::right << annualPropTax << endl;
//Displays Quarterly Property tax
cout << "Quarterly Property Tax" << setw(8) << "$ " << std::left << quarterlyTax;
cout << endl << endl;
}
这是当前输出:
Assessment: $ 175000.00
Annual Property Tax $ 7177.50
Quarterly Property Tax $ 1780.63
我需要它做的是显示如下:
Assessment: $ 175000.00
Annual Property Tax $ 7177.50
Quarterly Property Tax $ 1780.63
我想它应该是主动的。还将setw
添加到第二次打印中:
cout << "Assessment: " << setw(18) << "$ " << setw(10) << std::right << srAssessment << endl;
// ^^^^^^^^^^^^^^^^^^^^^^^^^
cout << "Annual Property Tax" << setw(11) << "$ " << setw(10) << std::right << annualPropTax << endl;
// ^^^^^^^^^^^
cout << "Quarterly Property Tax" << setw(8) << "$ " << setw(10) << std::right << quarterlyTax;
// ^^^^^^^^^^^^^^^^^^^^^^^^^
在 cout 语句中添加
这是另一个相关的堆栈溢出帖子:正确对齐C++输出流
std::cout << std::right << std::setw(x) << "output";
其中 x 是一个整数,表示以下"输出"的宽度。
相关文章:
- 了解 Linux 虚拟内存:valgrind 的 massif 输出显示了有和没有 --pages-as-heap 的主要差异
- 输出显示多个带整数的字符串值
- 如何使代码的输出显示为"工资减税"
- 如何让我的输出显示输入金额的星号
- 控制台输出显示ASCII值,而不是数字的预期数字
- 如何修复输出显示,以便显示正确排序的数据
- Android Studio 3.2:cmake message()输出显示在哪里
- 如何将OpenCV的输出显示或流式传输到HTML页面或其他一些客户端应用程序
- 我写了一个函数来删除循环链接列表中的第 1 个节点,但输出显示无限次"55 44 33 22 11 99",那么我该如何解决呢?
- 从c++程序运行shell脚本会自动将shell脚本的输出显示到控制台吗
- 为什么我的输出显示显示计算器中的每个选项
- C++将输出显示到php中
- 从 PHP 调用 C++ 应用程序 - 输出显示"Array"
- 有没有办法C++让循环的输出显示在同一行上
- 为什么日志输出显示在控制台主机中,而不显示在ISE中?(v4.0)
- 如何让GDB为每一行输出显示时间戳
- 为什么输出显示为无符号数
- 如何获得gdb tui汇编输出显示指令
- 为什么输出显示错误
- FFTW输入输出显示DSP