Indenting Text with PWB

Type the following program fragment:

#include <stdio.h>

#include <math.h>

main()

{

float pv, rate, pmt, fv, ratepct;

int nper, actnper;

// get input from the user

printf( "Enter present value:\n" );

scanf( "%f", &pv );

printf( "Enter interest rate in percent:\n" );

scanf( "%f", &rate );

printf( "Enter number of periods in years:\n" );

scanf( "%i", &nper );

}

Often you will add several lines indented to the same column. PWB saves you time by automatically indenting new lines when you press the ENTER key.

When the PWB C extension is loaded, PWB automatically indents new lines in C and C++ source files as appropriate for the C and C++ languages. When the language extension is not loaded (or the extension's autoindentation is turned off), PWB uses its default indentation rules as follows:

If there is no line or a blank line immediately below the new line, PWB matches the indentation of the line above it.

If there is a line immediately below the new line, PWB matches the indentation of the line below it.

You'll now type some text after the last scanf statement.

·To insert space for a new line:

1.Position the mouse cursor anywhere past the end of the scanf statement. Precise positioning of the cursor is not critical because (by default) PWB trims trailing spaces from the end of your lines.

2.Click the left mouse button.

3.Press ENTER to make a new line.

If you are in overtype mode, change to insert mode by pressing the INS key. Otherwise, pressing ENTER simply moves the cursor to the beginning of the next line. PWB displays the letter O on the status bar and shows the cursor as an underscore to signal that you are in overtype mode.

·To insert the new line using the keyboard:

1.Move the cursor to the scanf statement just above the closing brace by pressing the UP ARROW key.

2.Press END to move the cursor to the end of the line.

3.Press ENTER to make a new line.

Type the following lines:

ratepct = rate / 1200.0;

actnper = nper * 12;

// calculate the payment amount

pmt = pv * (ratepct / (1.0- (1.0 /

(pow((1.0 + ratepct), actnper )))));

printf( "Principal: %f\n", pv );

printf( "Interest rate: %f\n", rate );

When you enter the forward slash for the first comment line (the third line of this section), PWB's automatic indentation feature positions the cursor in column 5. To move the cursor to column 1, use the LEFT ARROW key or the BACKSPACE key.