Download presentation

Presentation is loading. Please wait.

Published byCornelius Mapp Modified over 2 years ago

1
Playing computer with logic problems Please use speaker notes for additional information!

2
start firstNum = 10 secondNum = 5 thirdNum = 1 theAns = 0 do while thirdNum < 10 if firstNum > 10 firstNum = firstNum + 5 secondNum = secondNum + 5 thirdNum = thirdNum + 5 else if secondNum > 10 firstNum = firstNum + 3 secondNum = secondNum + 3 thirdNum = thirdNum + 3 else secondNum = secondNum + 4 end if end while loop theAns = firstNum +secondNum + thirdNum display theAns end To start the program: firstNum secondNum thirdNum theAns 10 5 1 0 thirdNum = 1 so thirdNum is less then 10 so I move on to the first if statement firstNum = 10 so firstNum is NOT greater than 10 so I go to the else. secondNum = 5 so secondNum is NOT greater than 10 so I go to the else I add 4 to secondNum. Since secondNum started at 5, it is now 9. 5+4=9 NOW: firstNum secondNum thirdNum theAns 10 5 1 0 9 Now I drop through the end if, end if and end while loop and return to the do while statement to check and see if the loop should be done again.

3
start firstNum = 10 secondNum = 5 thirdNum = 1 theAns = 0 do while thirdNum < 10 if firstNum > 10 firstNum = firstNum + 5 secondNum = secondNum + 5 thirdNum = thirdNum + 5 else if secondNum > 10 firstNum = firstNum + 3 secondNum = secondNum + 3 thirdNum = thirdNum + 3 else secondNum = secondNum + 4 end if end while loop theAns = firstNum +secondNum + thirdNum display theAns end NOW: firstNum secondNum thirdNum theAns 10 5 1 0 9 thirdNumis 1 so it is still < 10 so I enter the loop firstNum is 10 so is NOT greater than 10 so I go to the else secondNum is 9 so is NOT greater than 10 so I go to the else I add 4 to second number which is currently 9. 9 + 4 equals 13 NOW: firstNum secondNum thirdNum theAns 10 5 1 0 9 13 Now I drop through the end if, end if and end while loop and return to the do while statement to check and see if the loop should be done again.

4
start firstNum = 10 secondNum = 5 thirdNum = 1 theAns = 0 do while thirdNum < 10 if firstNum > 10 firstNum = firstNum + 5 secondNum = secondNum + 5 thirdNum = thirdNum + 5 else if secondNum > 10 firstNum = firstNum + 3 + 3 secondNum = secondNum + 3 thirdNum = thirdNum + 3 else secondNum = secondNum + 4 end if end while loop theAns = firstNum +secondNum + thirdNum display theAns end NOW: firstNum secondNum thirdNum theAns 10 5 1 0 9 13 thirdNum is still 1 and that means it is less than 10, so I enter the loop. firstNum is 10 so it is still not greater than 10 so I go to the else. secondNum is 13 so secondNum is greater than 10 so I execute the three statements under that it. NOW: firstNum secondNum thirdNum theAns 10 5 1 0 9 13 13 16 4 Now I drop through the end if, end if and end while loop and return to the do while statement to check and see if the loop should be done again.

5
start firstNum = 10 secondNum = 5 thirdNum = 1 theAns = 0 do while thirdNum < 10 if firstNum > 10 firstNum = firstNum + 5 secondNum = secondNum + 5 thirdNum = thirdNum + 5 else if secondNum > 10 firstNum = firstNum + 3 + 3 secondNum = secondNum + 3 thirdNum = thirdNum + 3 else secondNum = secondNum + 4 end if end while loop theAns = firstNum +secondNum + thirdNum display theAns NOW: firstNum secondNum thirdNum theAns 10 5 1 0 9 13 13 16 4 thirdNum is 4 and that means it is still less than 10, so I enter the loop. firstNum is 13 so it is greater than 10 so I execute the statements in the if by adding 5 to the numbers NOW: firstNum secondNum thirdNum theAns 10 5 1 0 9 13 13 16 4 18 21 9 Now I drop through the end if and end while loop and return to the do while statement to check and see if the loop should be done again. Note that I do not enter the else on the first if so I do not ask the second question.

6
start firstNum = 10 secondNum = 5 thirdNum = 1 theAns = 0 do while thirdNum < 10 if firstNum > 10 firstNum = firstNum + 5 secondNum = secondNum + 5 thirdNum = thirdNum + 5 else if secondNum > 10 firstNum = firstNum + 3 + 3 secondNum = secondNum + 3 thirdNum = thirdNum + 3 else secondNum = secondNum + 4 end if end while loop theAns = firstNum +secondNum + thirdNum display theAns NOW: firstNum secondNum thirdNum theAns 10 5 1 0 9 13 13 16 4 18 21 9 23 26 14 thirdNum is 9. The do while says to enter the loop if thirdNum is less then 10, so I enter the loop. firstNum is 18 so the answer to the firstNum > 10 question is yes and I execute the three commands. NOW: firstNum secondNum thirdNum theAns 10 5 1 0 9 13 13 16 4 18 21 9 Now I drop through the end if and end while loop and return to the do while statement to check and see if the loop should be done again. Note that I do not enter the else on the first if so I do not ask the second question.

7
start firstNum = 10 secondNum = 5 thirdNum = 1 theAns = 0 do while thirdNum < 10 if firstNum > 10 firstNum = firstNum + 5 secondNum = secondNum + 5 thirdNum = thirdNum + 5 else if secondNum > 10 firstNum = firstNum + 3 + 3 secondNum = secondNum + 3 thirdNum = thirdNum + 3 else secondNum = secondNum + 4 end if end while loop theAns = firstNum +secondNum + thirdNum display theAns NOW: firstNum secondNum thirdNum theAns 10 5 1 0 9 13 13 16 4 18 21 9 23 26 14 thirdNum is 14 so it is no longer less than 10. This means that I do not enter the loop. When I drop out of the loop, I execute the sentence immediately after the end while loop. theAns = 23 + 26 + 14 theAns = 63 23 will be displayed on the screen

Similar presentations

OK

6/2/2014 1 Online Group Enrollment. 6/2/2014 2 Introduction Thank you for choosing Online Enrollment! This presentation will walk you through the Online.

6/2/2014 1 Online Group Enrollment. 6/2/2014 2 Introduction Thank you for choosing Online Enrollment! This presentation will walk you through the Online.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on polynomials of 92 Ppt on electromagnetism theory Esi ms ppt online Ppt on stock exchange-bse-nse Ppt on basic computer organisation Ppt on kinds of dependent clauses Ppt on nitrogen cycle and nitrogen fixation is a process Ppt on simple distillation and fractional distillation Ppt on odisha culture of india Ppt on business plan of restaurant