From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Solution: Using printf placeholders - C Tutorial
From the course: Complete Guide to C Programming Foundations
Solution: Using printf placeholders
(upbeat music) - [Instructor] The challenge calls for three variables, a character, an integer, and a float. These are mine, and the names I've chosen. I'm also assigning the values as the variables are declared, which saves quite a few statements. The first print F statement outputs a summary. You have purchased percent D, percent S at percent.2F each. These are the placeholders that match the data type. Percent D for decimal integer, the quantity. Percent S for the string item, and percent.2F for the real number price with only two digits after the decimal. You also see the dollar sign here. This is not part of the print F formatting command. It is simply to put a dollar sign in the output. The second print F statement outputs the total cost, again percent.2F to format that price, that total as a dollar amount, so only two digits after the decimal. The dollar sign again, is just for show. It's just a character. It is not a formatting command. Also, you see that I did the math right…
Contents
-
-
-
-
-
-
-
-
-
Using single character I/O3m 32s
-
(Locked)
Testing and converting characters3m 15s
-
(Locked)
Challenge: Character I/O and conversions34s
-
(Locked)
Solution: Character I/O and conversions1m 37s
-
(Locked)
Understanding strings in C2m 46s
-
(Locked)
Fetching string input3m 45s
-
(Locked)
Sending string output3m 41s
-
(Locked)
Challenge: Using printf placeholders1m 9s
-
(Locked)
Solution: Using printf placeholders1m 59s
-
(Locked)
Exploring string functions2m 41s
-
(Locked)
Manipulating strings2m 57s
-
(Locked)
Chapter challenge: Reading commands1m 52s
-
(Locked)
Chapter solution: Reading commands2m 31s
-
-
-
-
-