selection structure
Download
Skip this Video
Download Presentation
Selection Structure

Loading in 2 Seconds...

play fullscreen
1 / 11

Selection Structure - PowerPoint PPT Presentation


  • 93 Views
  • Uploaded on

Selection Structure. by Yonglei Tao. Conditional Statements. Write an algorithm that asks the user for two numbers , and print the larger one. Get the values of a, b from user If the value of a is greater than the value of b then print “The larger number is ” & a Else

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Selection Structure' - junius


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
selection structure

Selection Structure

by Yonglei Tao

conditional statements
Conditional Statements
  • Write an algorithm that asks the user for two numbers, and print the larger one.

Get the values of a, b from user

If the value of a is greater than the value of b then

print “The larger number is ” & a

Else

print “The larger number is ” & b

  • Test 1:What does the program print if the user enter 10, 3?
  • Test 2:What does the program print if the user enter 2, 11?
example
Example
  • Write an algorithm to compute the distance traveled and the average miles per gallon on a trip when given as input the number of gallons used and the starting and ending mileage readings on the odometer.

get gallons, start, end

distance = end – start

mpg = distance / gallons

print mpg

if mpg > 25.0 then

print “You are getting good gas mileage”

exercise
Exercise
  • Write an algorithm that asks the user to enter three numbers, and computes and prints out the largest number
ad