C++ Can';t似乎无法精确地排列十进制数字

C++ Can';t似乎无法精确地排列十进制数字,c++,input,io,iomanip,C++,Input,Io,Iomanip,我有一个简单的程序,询问一部电影的名称,以及set1和set2的门票销售量。然后用这些值进行计算并显示结果。我唯一的问题是,我似乎无法按照我希望的方式排列十进制值 控制台中的最后三行输出应该一直是这样的(美元符号和小数点对齐):。但是当我为票证的集合1输入1,为票证的集合2输入0,反之亦然,它看起来是这样的:。关于如何使输出始终像第一个屏幕截图中那样排列整齐,有什么想法吗?提前谢谢 #include <iostream> #include <string>

我有一个简单的程序,询问一部电影的名称,以及set1和set2的门票销售量。然后用这些值进行计算并显示结果。我唯一的问题是,我似乎无法按照我希望的方式排列十进制值

控制台中的最后三行输出应该一直是这样的(美元符号和小数点对齐):。但是当我为票证的集合1输入1,为票证的集合2输入0,反之亦然,它看起来是这样的:。关于如何使输出始终像第一个屏幕截图中那样排列整齐,有什么想法吗?提前谢谢

    #include <iostream>
    #include <string>
    #include <iomanip>

    using namespace std;

    int main() {

    string film = "";

    int set1 = 0;
    int set2 = 0;
    // the cinema always takes this 20% cut.
    const double CINEMA_FEE = 0.20;
    double profit = 0;
    double profitMinusFee = 0;
    double paidToMovieMaker = 0;

    cout << "What is the name of the film: ";
    getline(cin, film);

    cout << "How many tickets for set1 sold: ";
    cin >> set1;

    cout << "How many tickets for set2 sold: ";
    cin >> set2;

    cout << "Film Name:" << setw(20) << "\"" << film << "\"" << endl;
    cout << "Set1 tickets sold:" << setw(16) << set1 << endl;
    cout << "Set2 tickets sold:" << setw(16) << set2 << endl;

    set1 *= 10;
    set2 *= 6;
    profit = set1 + set2;
    profitMinusFee = profit * CINEMA_FEE;
    paidToMovieMaker = profit - profitMinusFee;
    // needs to always show two decimal points and fixed
    cout << setprecision(2) << fixed;
    cout << "The total monetary profit:" << setw(5) << "$ " << profit << endl;
    cout << "The net monetary profit:" << setw(7) << "$ " << profitMinusFee << endl;
    cout << "Total paid to movie maker:" << setw(5) << "$ " << paidToMovieMaker << endl;

    return 0;
    }
#包括
#包括
#包括
使用名称空间std;
int main(){
弦膜=”;
int set1=0;
int set2=0;
//电影院总是减价20%。
康斯特双影院费用=0.20;
双倍利润=0;
双profitMinusFee=0;
双paidToMovieMaker=0;
cout set1;
cout>set2;

我想你的问题是你在设定美元符号的宽度,而不是你的数字

这似乎为我解决了问题:

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main() {

    string film = "";

    int set1 = 0;
    int set2 = 0;
    // the cinema always takes this 20% cut.
    const double CINEMA_FEE = 0.20;
    double profit = 0;
    double profitMinusFee = 0;
    double paidToMovieMaker = 0;

    cout << "What is the name of the film: ";
    getline(cin, film);

    cout << "How many tickets for set1 sold: ";
    cin >> set1;

    cout << "How many tickets for set2 sold: ";
    cin >> set2;

    cout << "Film Name:" << setw(20) << "\"" << film << "\"" << endl;
    cout << "Set1 tickets sold:" << setw(16) << set1 << endl;
    cout << "Set2 tickets sold:" << setw(16) << set2 << endl;

    set1 *= 10;
    set2 *= 6;
    profit = set1 + set2;
    profitMinusFee = profit * CINEMA_FEE;
    paidToMovieMaker = profit - profitMinusFee;
    // needs to always show two decimal points and fixed
    cout << setprecision(2) << fixed;
    cout << "The total monetary profit: $ " << setw(10) << profit << endl;
    cout << "The net monetary profit  : $ " << setw(10) << profitMinusFee << endl;
    cout << "Total paid to movie maker: $ " << setw(10) << paidToMovieMaker << endl;

    return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main(){
弦膜=”;
int set1=0;
int set2=0;
//电影院总是减价20%。
康斯特双影院费用=0.20;
双倍利润=0;
双profitMinusFee=0;
双paidToMovieMaker=0;
cout set1;
cout>set2;

你能搞定吗?这么简单,但我错过了!谢谢你,先生。