终端与Xcode的输出问题。感谢任何能告诉我自己做错事的人。
简单程序:
/* Military officer: age, rank, serial number, base pay, and number of years in service */
#include < stdio.h>
int main()
{
int age, rank, ss1, ss2, ss3;
float base_pay, years;
/* Ask User to Input Various Entries */
printf("Enter officer age: ");
scanf("%d", &age);
printf("Enter officer rank (e.g. 3 for captain): ");
scanf("%d", &rank);
printf("Enter serial number (e.g. 000-00-0000): ");
scanf("%d -%d -%d", &ss1, &ss2, &ss3);
printf("Enter base pay: ");
scanf("%f", &base_pay);
printf("Enter number of years in service: ");
scanf("%f", &years);
/* Output of Entries */
printf("\nOfficer\t\t\tOfficer\t\t\tSerial\t\t\tBase\t\tYears\n");
printf("Age\t\t\tRank\t\t\tNumber\t\t\tPay\t\tin\n");
printf("\t\t\t\t\t\t\t\t\t(USD)\t\tService\n\n");
printf("=======\t\t\t=======\t\t\t===========\t\t=========\t=======\n\n");
printf("%-d\t\t\tO-%-d\t\t\t%-.3d-%.2d-%.4d\t\t$%-.2f\t%-10.1f\n\n", age, rank, ss1, ss2, ss3, base_pay, years);
return 0;
}
答案 0 :(得分:0)
可能是“\ t”他们之间的行为不同。
答案 1 :(得分:0)
输出问题是由于打印格式(太多\ t出现)非常容易出错,尽管看起来不错。我建议牺牲一些美学,只需打印属性名称后跟其值,如下所示:
printf("Age: %d\n", age);
其他人跟着。