打印表 C++

发布于 2024-12-09 00:44:10 字数 1121 浏览 0 评论 0原文

我正在尝试打印一个如下所示的表格:

                       Number of Queues

 Oc           2               3             4              5
50,000   average-max    average-max    average-max   average-max
100,000  average-max    average-max    average-max   average-max
150,000  average-max    average-max    average-max   average-max

等等,

其中平均值是 getAverage() ,最大值是 getMax() 。

amount 包含步进的 Oc 值。

我一直试图用来执行此操作的代码如下:

cout << setw(5) << "Oc" << setw(10) << "2" << setw(5) << "3" << setw(5) << "4" << setw(5) << "5" << endl << endl;

while (amount < 400000)
{
        amount += 50000;

        for (int i = 2; i <= 5; i++)    //2 and 5 for the number of queues
        {   
            Simulator simulator(i, amount);

            simulator.start();

            cout << setw(5) << amount << setw(10) << simulator.getAverage() << "-" << simulator.getMax();

        } //end for loop

} //end while loop

我需要一些帮助来修复此问题以正确显示表格,目前它到处都是。

I am trying to print a table that looks like this:

                       Number of Queues

 Oc           2               3             4              5
50,000   average-max    average-max    average-max   average-max
100,000  average-max    average-max    average-max   average-max
150,000  average-max    average-max    average-max   average-max

etc etc

where average is the getAverage() and max is the getMax().

amount contains the stepped Oc value.

The code I have been trying to use to do this is below:

cout << setw(5) << "Oc" << setw(10) << "2" << setw(5) << "3" << setw(5) << "4" << setw(5) << "5" << endl << endl;

while (amount < 400000)
{
        amount += 50000;

        for (int i = 2; i <= 5; i++)    //2 and 5 for the number of queues
        {   
            Simulator simulator(i, amount);

            simulator.start();

            cout << setw(5) << amount << setw(10) << simulator.getAverage() << "-" << simulator.getMax();

        } //end for loop

} //end while loop

I need some help fixing this to display the table properly, it's all over the place at the moment.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〃温暖了心ぐ 2024-12-16 00:44:10
while (amount < 400000)
{
        amount += 50000;

        for (int i = 2; i <= 5; i++)    //2 and 5 for the number of queues
        {   
            Simulator simulator(i, amount);

            simulator.start();

            cout << setw(5) << amount << setw(10) << simulator.getAverage() << "-" << simulator.getMax() << "\t";

        } //end for loop

} //end while loop

您可以使用“\t”

while (amount < 400000)
{
        amount += 50000;

        for (int i = 2; i <= 5; i++)    //2 and 5 for the number of queues
        {   
            Simulator simulator(i, amount);

            simulator.start();

            cout << setw(5) << amount << setw(10) << simulator.getAverage() << "-" << simulator.getMax() << "\t";

        } //end for loop

} //end while loop

You can use "\t"

骷髅 2024-12-16 00:44:10
cout << setw(6) << "Oc" << setw(10) << "2" << setw(10) << "3" << setw(10) << "4" << setw(10) << "5" << endl << endl;

while (amount < 400000)
{
        amount += 50000;
        cout << setw(5) << amount;
        for (int i = 2; i <= 5; i++)    //2 and 5 for the number of queues
        {   
            Simulator simulator(i, amount);

            simulator.start();

             cout << setw(10) << simulator.getAverage() << "-" << simulator.getMax();

        } //end for loop
        cout << endl;   

} //end while loop

祝你好运

cout << setw(6) << "Oc" << setw(10) << "2" << setw(10) << "3" << setw(10) << "4" << setw(10) << "5" << endl << endl;

while (amount < 400000)
{
        amount += 50000;
        cout << setw(5) << amount;
        for (int i = 2; i <= 5; i++)    //2 and 5 for the number of queues
        {   
            Simulator simulator(i, amount);

            simulator.start();

             cout << setw(10) << simulator.getAverage() << "-" << simulator.getMax();

        } //end for loop
        cout << endl;   

} //end while loop

Good luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文