大家好!!
C++中不知如何調整輸出的版面阿?
題目是這樣的:
#include
using namespace std;
// function main begins program execution
void main(void)
{
int v=58, t=0;
cout << "Enter the travel time-->";
cin >> t;
cout << " V(Velocity) T(Time) A(Acceleration) D(Distance)\n";
cout << v;
cout << t;
// print the title and the results of "v(velocity)" and "t(time)"
for (int a=1; a<6; a++)
// loop when "a(acceleration)" is less than 6
{
cout << a <<" "
<< v*t+0.5*a*t*t<
"d(distance)" which is equle to v*t+0.5*a*t*t */
}
}
// end function main
目前的輸出結果是:
Enter the travel time-->2(假設是2)
V(Velocity) T(Time) A(Acceleration) D(Distance)
58 2 1 118
2 120
3 122
4 124
5 126
但範例中的結果示範是:
V(Velocity) T(Time) A(Acceleration) D(Distance)
58 2 1 118
2 120
3 122
4 124
5 126
請問要如何寫這樣排版的語法呢?
2005-08-05 16:33:17 · 1 個解答 · 發問者 Anonymous in 電腦與網際網路 ➔ 程式設計
#include
cout << setw(n),n是你要空的格數…可以自己試試要空幾格
2005-08-05 17:01:54 · answer #1 · answered by 上官 5 · 0⤊ 0⤋