Control IV

Control IV - 1 Flow of Control Part IV Department of...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Flow of Control Part IV Department of Computer Science APSC 160 Flow of Control Part IV Learning Goals By the end of this section, you should be able to: read and write code that uses nested branching describe the circumstances under which braces are not required to define the start and end of a conditional block of code Nested branching Nested branching Nested branching Example: Write a program that prompts the user for their age and that prints the cost of a transit ticket according to the following scheme: If age < 0, print an error message otherwise, if age < 18, cost is $1.25 + tax otherwise, cost is $2.25 + tax Assume that the tax rate is 7%. 2 Flowchart Nested Branch Code if( age < MIN_CHILD_AGE ) { printf( "Error: age not valid.\n" ); } else { if( age < MIN_ADULT_AGE ) { fare = CHILD_FARE; } else { fare = ADULT_FARE; } total = fare * ( 1 + TAX_RATE ); printf( "Total fare: $%.2f\n", total ); } Code Example: Suppose we want to write a program that prompts the user for the...
View Full Document

Page1 / 3

Control IV - 1 Flow of Control Part IV Department of...

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