2

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

                       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

我需要一些帮助来解决这个问题以正确显示表格,目前它到处都是。

4

2 回答 2

2
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”

于 2011-10-09T01:13:43.600 回答
0
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

祝你好运

于 2018-12-18T09:22:54.837 回答