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

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