Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 141 Computer Programming 1 Branching Statements.

Similar presentations


Presentation on theme: "CS 141 Computer Programming 1 Branching Statements."— Presentation transcript:

1 CS 141 Computer Programming 1 Branching Statements

2 2 Question #1 Question Find the errors and correct them.. a. If x<0 cout<<x<<"is negative"; b. If(x=2) y++;else; if(x=3) y+=2;

3 3 Answer Question #1 a. If x<0 cout<<x<<"is negative"; b. If(x=2) y++;else; if(x=3) y+=2; if(x==2)y++; else if (x==3)y+=2; If (x<0) cout<<x<<"is negative";

4 4 Question #2 Question Modify the following code to produce the output shown. Use proper indentation techniques. You must not make any changes other than inserting braces

5 5 Question #2 Question

6 6 Question #2 Question Assuming x=5 and y=8, the following output is produced.

7 7 Question #2 Answer

8 8 Question #2 Question Assuming x=5 and y=7, the following output is produced.

9 9 Question #2 Answer

10 Problems 10

11 11 Problem #1 Question Write a program that asks the user to input his age and outputs whether he is older, younger or the same age as you.

12 12 Problem #1 Answer

13 13 Problem #2 Question Write a program that determines the maximum and the minimum of three numbers.

14 14 Problem #2 Answer

15 15 Problem #3 Question Write a program that checks the order of a medicine from a pharmacy store. The program should read the order quantity and the medicine quantity in the store. The messages that will be displayed in that cases are “ Your order is accepted ” OR “ You cannot order more than 16 item ” When the order quantity is more than the store quantity, your program should display the message “No enough quantity”. When the order quantity is less than the store quantity, you have to check that the order quantity must be not more than 16 except there is more than 40 items in the store.

16 16 Problem #3 Question

17 17 Problem #3 Answer

18 18 Problem #4 Question Write a program that calculates the areas of different shapes according to a character input signifying the shape: The necessary input should be read after the character. Hint: use case c for circle. r for rectangle. s for square. t for triangle.

19 19 Problem #4 Answer

20 20 Problem #5 Question Write a program to simulate a simple calculator. It should ask the user to enter a first number, the operation(as a character), and the second number. Addition, Subtraction, Division, Multiplication, and Modulus are the basic operations that should be implemented. (HINT: use case). Enter a mathematical Expression:2+4 The result is:2+4=6

21 21 Problem #5 Answer

22 22 Problem #5 output

23 EVALUATION !! Hadeel Al-Ateeq 23

24 24 Problem #1 Question Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered by the user. A triangle is valid if the sum of all the three angles is equal to 180 degrees.

25 25 Problem #1 Answer


Download ppt "CS 141 Computer Programming 1 Branching Statements."

Similar presentations


Ads by Google