c++ - 先到先得程序 C++ 表格格式

标签 c++ formatting

<分区>

我被要求执行“先到先得”计划。我破解了代码,程序运行良好。但是我在表格列中显示它时遇到问题。

我希望它像这样显示:

Pr  AT  ST  WT  TAT RR
--------------------------
A   0   3   0   3   1
B   2   6   1   7   1.16
C   4   4   5   9   2.25
D   6   5   7   12  2.4
E   8   2   10  12  6

Average Response Ratio is 2.56  

但是我得到的是这样的: Output

在我输入姓名、到达时间和服务时间后,等待时间、周转时间和响应率出现在下一行。我希望所有的东西都出现在同一条线上。

谁能告诉我哪里出错了?这是我的代码:

//First Come First Serve Scheduling
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
 int at[5],st[5],tt=0,wt=0,tr=0;
 char name[5];
 float res,tres;
 clrscr();
 cout<<"\n\tName \tAT \tST \tWT \tTAT \tRR";
 for(int i=0;i<5;i++)
 {
  cout<<"\n\t";
  cin>>name[i];
  cout<<"\t";
  cin>>at[i];
  cout<<"\t";
  cin>>st[i];
  wt = tr - at[i];
  cout<<"\t\t"<<wt;
  tt = wt + st[i];
  cout<<"\t"<<tt;
  tr+=st[i];
  res=(float)tt/st[i];
  tres+=(float)res;
  cout<<"\t"<<res;
  }
  cout<<"\nAverage response ratio is: "<<tres/5;
 getch();
}

任何帮助都会非常好。谢谢你们。

最佳答案

C++程序不处理换行符,在Windows平台下或许可以试试Windows Console APIs或 curse 库(例如 ncurse)来更改光标的位置。或者您可以简单地编写自己的函数来处理输入。在那种情况下,您应该放弃 std:cin。

关于c++ - 先到先得程序 C++ 表格格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14545218/

相关文章:

android - 在 Android Studio 中重新格式化整个项目文件

c++ - 为什么我需要在 Less Traits 中使用 const 函数

c++ - 本地构建工作正常时没有这样的文件或目录

java - 在 Java Swing 中放置组件

c# - DateTime.ParseExact AM/PM 指标小写

java - Play 2.0 中带有泛型的自定义格式化程序

php - 使用 PHP 解析 JSON

C++ 堆栈推送/打印实现

c# - Windows 上的字体名称是否只有英文?

python - OpenCV 相机标定旋转 vector 到矩阵