Name the pieces
A string literal encloses text in double quotes. Inside "Total: " the final space separates the label from the price. Outside quotes, label refers to the value introduced by let. Writing "label" would print those five letters.
Assemble a line
print!(label) writes the label and leaves the cursor on that line. println!(cost) writes the integer and ends the line. The last call starts a new line with Paid. To display several values together, use consecutive calls. These macros take zero or one expression.
Write a useful comment
A // comment continues to the end of its line. A comment such as // price is in whole credits records the unit that the number alone cannot express. Put the calculation in a binding if you want to print it twice.
Read output precisely
An extra space, a missing line break or putting the numeric expression inside quotes can change a report. First compare the lines and then compare characters within each line. This is the same approach you can use when testing a longer program.
Try the program
Expected output
Total: 21 Paid
Practice
Change the quantity from three to five and replace the final receipt line with Thanks.
Hint
Edit the expression that defines cost, then edit the last quoted string.
Worked solution
Five units at seven credits cost 35. print! keeps the label and total on the same line.
Find
3 * 7Replace with
5 * 7Find
"Paid"Replace with
"Thanks"Output after the change
Total: 35 Thanks