3.6 Detecting ranges with if-else statements

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the range for the last branch below? if (numItems < 0) { ... } else if (numItems > 100) { ... } else { // Range: ______ ... }

0-100`

If the final else branch executes, what must userNum have been? Type "unknown" if appropriate. if (userNum <= 9) { ... } else if (userNum >= 11) { ... } else { ... // userNum if this executes? }

10

Type the range for each branch. Type ranges as: 25 - 29, or type 30+ for all numbers 30 and larger. if (numSales < 10) { ... } else if (numSales < 20) { // 2nd branch range: _____ ... } else if (numSales < 30) { // 3rd branch range: _____ ... } else { // 4th branch range: _____ ... } 2nd branch range: ________

10-19

Type the range for each branch. Type ranges as: 25 - 29, or type 30+ for all numbers 30 and larger. if (numSales < 10) { ... } else if (numSales < 20) { // 2nd branch range: _____ ... } else if (numSales < 30) { // 3rd branch range: _____ ... } else { // 4th branch range: _____ ... } 3rd branch range: __________

20-29

Type the range for each branch. Type ranges as: 25 - 29, or type 30+ for all numbers 30 and larger. if (numSales < 10) { ... } else if (numSales < 20) { // 2nd branch range: _____ ... } else if (numSales < 30) { // 3rd branch range: _____ ... } else { // 4th branch range: _____ ... } 4th branch range: ____________

30+

Second branch: userNum is positive (non-zero) if (userNum < 0 ) { ... } _________________________ { ... } else { // userNum is 0 ... }

else if (userNum > 0)

Second branch: userNum is greater than 105 if (userNum < 100 ) { ... } _________________________ { ... } else { // userNum is between // 100 and 105 ... }

else if (userNum > 105)

Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Else, if givenYear is 2001 or greater (2001-2100), print "21st century". Else, if givenYear is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago". Do NOT end with newline. #include <iostream> using namespace std; int main() { int givenYear; givenYear = 1776; /* Your solution goes here */ return 0; }

if (givenYear >= 2101) { cout << "Distant future"; } else if (givenYear >= 2001) { cout << "21st century"; } else if (givenYear >=1901) { cout<<"20th century"; } else { cout << "Long ago"; }

Which branch will execute? Valid answers: 1, 2, 3, or none. userNum = 555; if (userNum < 0) { ... // Branch 1 } else if (userNum == 0) { ... // Branch 2 } else if (userNum < 100) { ... // Branch 3 }

none

Second branch: userNum is less than 200 if (userNum < 100 ) { ... } else if (________________________) { ... } else { // userNum >= 200 ... }

userNum < 200, or userNum <= 199


Ensembles d'études connexes

Anatomical positions/ planes/ movements

View Set

Topic Auditor Responsibility (week 2)

View Set

Macro Economics Chapter 5 Quiz Review

View Set

Adaptive Quizzing Review for CAT (102,103,104)

View Set

reading 35 - Working Capital Management

View Set

Vision, hearing, vestibular disorders

View Set

Social Problems Chapter 12: Population Growth and Aging

View Set

Chemistry Review: Chapter 4 The Structure of the Atom

View Set

Path 370 Assessment 3 (CH. 16, 18, 19, 20)

View Set

Introduction to Communication Final Exam

View Set