如何使用printf打印此示例输出?
******************************************************************************
** XYZ Corporation Date: March 27, 1989(Use current date)**
** 999 John Doe street **
** Ypsilanti, MI. 48197. **
** **
** Pay to the order of: ? **
** The amount of: ? dollars, and ? cents **
** **
** signed: **
** President, XYZ Corporation. **
** **
**--------------------------------------------------------------------------**
** SUMMARY **
** Social security number: ? **
** Regular pay: ? **
** Overtime pay: ? **
** Gross pay: ? **
** Federal tax: ? **
** Social sec. deduction: ? **
** City tax: ? **
** Union dues: ? **
** Net pay: ? **
** **
******************************************************************************
Run Code Online (Sandbox Code Playgroud)
我试过了,但我不确定我是不对的:
printf"
XYZ Corporation Date:
999 John Doe street
Ypsilanti, MI. 48197
Pay to the order of: |
The amount of: | dollars, and | cents
signed:
President, XYZ Corporation.
--------------------------------------------------------------------------
SUMMARY
Social security number: $ssn
Regular pay: %-.2f
Overtime pay: %-.2f
Gross pay: %-.2f
Federal tax: %-.2f
Social sec. deduction: %-.2f
City tax: %-.2f
Union dues: %-.2f
Net pay: %-.2f\n", $regPay, $overPay, $grossPay, $fedTax, $ssnDeduction, $cityTax, $unionDues, $netPay;
Run Code Online (Sandbox Code Playgroud)
谁能帮我?我确定我的作业不正确,但我只是想知道解决方案.
我认为你不应该在这里使用printf.这似乎是Perl format功能的完美应用.这些语言自成立以来一直在使用,因此Perl被认为是"实用提取和报告语言"的首字母缩写.我从未使用过格式,但您可以在本教程中了解更多信息:http://www.webreference.com/programming/perl/format/index.html
据我所知,这是一个在过去二十年中变化很小的功能,因此您在网络上发现的任何内容都应该为您提供有用的帮助.
| 归档时间: |
|
| 查看次数: |
307 次 |
| 最近记录: |