Display amount of sale and the amount each of these

This preview shows page 7 - 9 out of 19 pages.

Display "Employee #" and the empnum.Display "Amount of sale: $" and the amount.Each of these lines indicates what is to happen, but in a descriptive way in English rather than in the syntax of C. The terms I used are common, but are not standard. There is, in fact, an official standardized pseudocode, but that is akin to another language with syntax rules, and for you (introductory students) that defeats the purpose.We are trying to make it easy for you to express what you would like to have happen in the program. So focus on a simple English description, and that should suffice. As you learn more programming, your pseudocode statements will most likely start to appear more terse.I'll show another example of pseudocode later on in Module 3B.An Alternative to the Limited scanf() Function for String Inputscanf() has many limitations when working with strings, one of which being the inability to read blank spaces as part of the string. This is major, as manyfirst and last names, addresses, cities, states and countries would be completely unreadable because they have a space in the middle.Fortunately, a more forgiving functions exists within C that can be used for reading strings. It is called gets(). It requires only one argument (remember, an argument is one of the elements inside the parentheses), and that is the string variable which will be receiving the input. The value read can have oneor more spaces. Here's another example of 3-4 that uses this function.You will still see many programs use scanf() to read in string and character values. There are options in scanf() that we will not be discussing that make it powerful in certain instances. I will use scanf() and gets() interchangeably throughout the course, if reading a space is not an issue.Numbers still must be read using scanf(). Output FormattingOutput Formatting - Lecture and DemonstrationClick to view undefined
Example 3-5introduces output formatting for float values. Output formatting occurs directly in the printf statement. Immediately after the % in the printing spec for the float number that we're printing, we place the field-width specification. The field-width specification indicates two things: 1) the number of print positions then we want the values to take up on the output line and 2) the number of decimal places we'd like printed. C rounds the number to those two decimal places. So, if the user enters 345.67 as the amount in this program, after the "Amount of sale: " string literal we will have two blank spaces followed by 345.67. C prints the value right justified in a field of 8 print positions. (Right justified means to push value as far right as possible.) Because 345.67 requires six print positions, C automatically pads the number with two blank spaces on the left.If the field-width specification for this example had been 8.3, the output would have been one blank space followed by 345.670. And, if the field-widthspecification was 8:1, the output would have been three blank spaces followed by 345.7. C would have rounded the number to one decimal place.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture