2016-02-20 42 views
-2

How the code looks printed如何在C++中打印字母和符號後保留在一個地方?

How I want the code to look when printed(not the numbers just the colon:)

不同的方法,我試圖從移動保持結腸\

printf("COURSE GRADE : POINTS NEEDED ON FINAL  : PERCENTAGE NEEDED ON FINAL\n"); 
printf("A    : %d       : %5.2f%%\n", neededA, percentA); 
printf("B    : %d       %c %5.2f%%\n", neededB, 58, percentB); 
printf("C %14c %d %24c %5.2f%%\n", 58, neededC, 58, percentC); 
printf("D    : %d       %0c %5.2f%%\n", neededD, 58, percentD); 
+4

您的移位鍵可能會被卡住。你可能想投資一個新的鍵盤。我們真的不喜歡在這裏被淘汰 - 這真是粗魯和惱人。它甚至會在你懷**的時候變得更加糟糕,因爲它表明你正在嘗試着**甚至更糟糕的**。請降低你的聲音。 –

+0

使用'\ t'符號 – fnc12

+0

甜蜜感恩的傢伙 – Patrick

回答

0

如果您使用的printf,你應該讀了一下格式說明可以做。因爲它可以做你想做的事。

printf("%20d\n", 42); 

將確保打印的字段的寬度至少爲20個字形。 雖然像20這樣的正整數將導致使用負整數的右對齊字段導致左對齊的字段。

相關問題