Pseudocode

Pseudocode - Print out kilometers traveled gas consumed...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Pseudocode No data declarations in pseudocode. Pseudocode is your ‘algorithm’ – your ‘approach’ to solving the problem. It is your solution. Notice that this algorithm is ‘straight sequential processing’ No loops; no conditional computations. Straight sequential processing. <declarations as needed> Prompt user to enter starting odometer reading. Specify format (xx.xx or decimal format) Read in odometer reading (integer) Prompt user to enter ending odometer reading. Read in odometer reading (integer) Prompt user for gallons of gas consumed (specify decimal as in xx.xx) Read in gas consumed Computer total miles traveled (ending odometer – starting odometer) Divide miles traveled by gas consumed giving miles/gallon (mpg) Print header line: miles traveled gas consumed mileage” Print out miles traveled, gas consumed, and mileage under header line. Convert miles traveled to kilometers by multiplying miles * 1.61. Compute mileage as kilometers / gallons consumed ( better to use liters, but … )
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Print out kilometers traveled gas consumed mileage Print out kilometers traveled and kilometers / gallon. Stop More Examples Prompt user for values for x and y (integers) Read in values for x and y If x &gt; 15 // Selection Multiply x by 5.4 Print out value of new x // sequence within selection Else Print out value for y Endif If y &lt; 3 // Selection Divide y by 4 Multiply x by y giving new total End if Set a to 1. For a = 1 to 10 step by 1 // iteration Print out a End for Set I = 0 While (I &lt; 10) // iteration Multiply xxxxx Print . Increment I by 1 End-while For (j = 0, j &lt; 100, increment j by 1) // iteration Add Subtract Print Prompt Read in End for If a &gt; b Add 3 to total While total &lt; 345 (// as long as total is less than 345 do the following) Multiply xxxxx Divide xxxxxx Print out xxxxx Increment total by 20 End while Else Print Thats all folks End if...
View Full Document

Page1 / 3

Pseudocode - Print out kilometers traveled gas consumed...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online