You are on page 1of 9

# Exercise # ___ Title: Turbo C/C++ Conditional Statements

Pageno. Date:___

Objectives: y At the End of this exercise you should be able to understand the Turbo C/C++ Conditional statement syntax and to be able to create a program using conditional statements. Background Conditional Statements Format Single Statement Option 1 if(condition) statement; Option 2 if(condition) statement; else statement;

Option 3 if(condition) statement; else if(condition1) statement; . . . else if(conditionn) statement;

Example 1: if( age >= 18) printf(´\nQualified to voteµ);

Example 2: if( age >= 18) printf(´\nQualified to voteµ); else printf(´\nToo Young to voteµ);

Example 3: if( age >= 18) && (age <=100) printf(´\nQualified to voteµ); else if( age>=1) && (age <=17) printf(´\nToo Young to voteµ); else printf(´\nOut of rangeµ);

The program is to be given the plane·s observed speed in km/h and its estimated length in meters.Exercise no. The vowels are: A E I O U. 2. and shorter such as 500 km/h and 20 meters as ´militaryµ aircraft. you will issue an ´It·s a birdµ message. 7: Turbo C/C++ Conditional statements NAME: ____________________________________ SECTION: _______________ DATE: __________________ 1. . Write a program that determines if the input letter is a VOWEL or CONSONANT. For planes traveling at more slower speeds. and longer than 52 meters. Your program must be able to handle a capital or small input letter. For Planes traveling in excess of 1100 km/h. you should label them as ´civilianµ aircraft. Create a program flowchart for the Air Force to label an aircraft as military or civilian.

Write a program to assist a teacher in calculating student·s grade at the end of the semester.3. It accepts a numerical grade as input. then it will display character grade as output. based on the given scale: Range 90 and above 80 ² 89 70 ² 79 60 ² 69 Below 60 Grade A B C D F .

. execution starts at the case and end with a break statement. . case const-value2: statement1. break. statement. break. case const-valuen: statement1. statement. default: statements. statement. . Background Switch Case Statement The switch case statement is a multi-way decision that tests whether an expression matches one of a number of constant integer or character values and branches accordingly. break. Date:___ Objectives: y At the End of this exercise you should be able to understand the Turbo C/C++ Switch Case statement syntax and to be able to create a program using switch case statements.Exercise # ___ Title: Turbo C/C++ Switch Case Statements Pageno. . Format: switch(expression) case const-value1: statement1. If the case matches the expression value.

sum). printf(´\nThe sum is %dµ.&choice). printf(´\nThe product is %dµ. case 3: product = a * b. clrscr().diff.&a.h> #include<conio. scanf(´%dµ. } . break. int sum. break.Sample Problem 1: Write a program that will ask the user to input two numbers and let him/her choose what to compute. break. int choice.b. printf(´\nThe diff is %dµ. printf(´\n1]sum\n2]difference\n3]productµ).product).product. case 2: diff = a .diff). clrscr() printf(´\nInput 2 nos:µ). } getch().h> main() { int a. Solution: #include<stdio. scanf(´%d%dµ. such as 1]sum 2]diff 3]product. switch(choice) { case 1: sum = a + b.&b).b. printf(´\nchoice:µ).

sum). switch(choice) { case ¶a·: case ¶A·: sum = a + b. printf(´\nThe sum is %dµ. scanf(´%d%dµ.h> #include<conio.Sample Problem 2: Write a program that will ask the user to input two numbers and let him/her choose what to compute. printf(´\nThe diff is %dµ. } getch().b. clrscr().b. int sum. case ¶b· case ¶B·: diff = a .&a. scanf(´%cµ.&b).h> main() { int a. Solution: #include<stdio. such as A]sum B]diff C]product. printf(´\nThe product is %dµ. break.&choice).product).diff). char choice. } . choice = getchar(). clrscr() printf(´\nInput 2 nos:µ). break. break. printf(´\nchoice:µ). printf(´\n1]sum\n2]difference\n3]productµ).product. case ¶c· case ¶C·: product = a * b.diff.

The vowels are: A E I O U. 7: Turbo C/C++ Conditional statements NAME: ____________________________________ SECTION: _______________ DATE: __________________ 1. Write a program that determines if the input letter is a VOWEL or CONSONANT. and shorter such as 500 km/h and 20 meters as ´militaryµ aircraft. For Planes traveling in excess of 1100 km/h. Create a program for the Air Force to label an aircraft as military or civilian. . you should label them as ´civilianµ aircraft.Exercise no. 2. For planes traveling at more slower speeds. you will issue an ´It·s a birdµ message. The program is to be given the plane·s observed speed in km/h and its estimated length in meters. and longer than 52 meters. Your program must be able to handle a capital or small input letter.

Write a program that accepts a number and outputs its equivalent in words.1.(use extra sheet of paper if needed) Sample input/output dialogue: Enter a number : 1380 One thousand three hundred eighty Take note that the maximum input number is 3000. .