Example 2 -
Write a program that converts feet to inches. Prompt the user for feet and display the equivalent number of inches. Have your program repeat this process until the user enters 0 for the number of feet.

(a) By looking at the question, we can see that we need two variables.One for feet and one for inches.

Since something can measure a fraction of a foot or a fraction of an inch, these two variables can be floating-point numbers.

(b) Next, we need to understand how the calculation is to be performed.

1 foot = 12 inches is the conversion. So we can simply multiply feet by 12 to get the desired value for inches.

(c) We are to prompt for input repeatedly until the user enters 0 for the number of feet.

Any method of looping would be acceptable. In this example we will use a while loop.

(d) Again, we must prompt the user for input, so we have to include the <iostream.h> library.

(e) We want to use functions in this example. So we will have 2 - one for the user prompt (a void function) and a second for the calculation (one that returns a floating-point number that represents inches).
Our resulting pseudo-code is as follows:
#include <iostream.h>
declare function for prompt; //does not have a return type or any parameters
declare function for conversion; //returns a floating-point number representing inches
//and also requires a floating-point number as a parameter, representing feet
int main() {
declare 2 floating-point variables: feet and inches;
output to screen what program does;
/* now because a floating-point number may not evaluate precisely to zero,
we may choose to have our loop to be controlled by a boolean variable rather than a direct comparison of (inches == 0) */
declare a boolean variable isZero and initialize to false;
begin while (! isZero) {
call prompt function;
accept input from keyboard for feet;
if (feet == 0) set isZero to true;
else inches = conversion(feet);
} //end while
} // end main.
begin prompt function definition {
output request to screen for a value to represent feet;
} //end prompt function definition
begin conversion function definition {
return (feet * 12);
} //end conversion function definition

Now we can code in C++. View the source code.