How can you model playing rock-paper-scissors?

Slides:



Advertisements
Similar presentations
E.g.9 For to do loop for i:=1 to 10 do writeln(i); While do loop i:=1;
Advertisements

Looping Structures: Do Loops
Lecture 4: Javascript Basics Javascript is a scripting language based on pieces of C, C++, shell scripts, Pascal, Java, etc. Scripts – loosely typed C++
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Looping while … do …. Condition Process 2 Process 1 Y Repeated Loop.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
James Tam Repetition In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
J. Michael Moore Other Control Structures CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
CS150 Introduction to Computer Science 1
James Tam Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
James Tam Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate your code.
J. Michael Moore Other Control Structures CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Previously Repetition Structures While, Do-While, For.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
For loops in programming Assumes you have seen assignment statements and print statements.
1. Understand the application of Pseudo Code for programming purposes 2. Be able to write algorithms in Pseudo Code.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
End of unit assessment Challenge 1 & 2. Course summary So far in this course you have learnt about and used: Syntax Output to screen (PRINT) Variables.
Loops Brent M. Dingle Texas A&M University Chapter 7 – part B (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 11.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Computer Science 101 For Statement. For-Statement The For-Statement is a loop statement that is especially convenient for loops that are to be executed.
Design Document Sample Given two concentrated circles with different radii, calculate the area which falls inside the big circle but outside the small.
UCT Department of Computer Science Computer Science 1015F Iteration
The Solar System. Mercury Mercury is the closest planet to the sun. Mercury is the closest planet to the sun.
15.1 More About High-Level Programming Languages Syntax and Semantics Each programming language contains its own rules for both syntax and semantics. Syntax.
7 - Programming 7J, K, L, M, N, O – Handling Data.
The Solar System by Sadie Hudson Comments and Future Considerations:
Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code. Repetition in Pascal:
Writing Functions( ) (Part 5)
Program options Write a program for one of the following
Introduction to pseudocode
CS1100 Computational Engineering
Computer Science 1 Online time to complete/enhance second repeat program Be able to read and write a program that uses the ‘case’ statement.
Intro to Nested Looping
Review Dry Run Taking Names Online time Math is Good
Computer Science 1 Get out your notebook
Dry run Fix Random Numbers
Three Special Structures – Case, Do While, and Do Until
Repeat Day2 Dry Run Second Repeat Program
Intro to Nested Looping
Computer Science 1 Warm-up: True/False Dry Run
The first number is posted telling what random number was selected, I did this for testing purposes, in the real thing it would not be there. Since the.
How can you model playing rock-paper-scissors?
How can you make a guessing game?
Computer Science 1 while
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Decisions, decisions, decisions
How can you make a guessing game?
Computer Science
Computer Science I: Get out your notes.
How can you model playing rock-paper-scissors?
The Solar System.
Program options Write a program for one of the following
Computer Science 1 while
The Solar System.
10/27/2016 Dry Run 2 Case Programs Fix it Second Case Program
Computer Science 1 while
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
Computer Science 1 Get out your notebook
Computer Science 1 Get out your notebook
Dry Run Fix it Write a program
A bit of Review Review, Dry Run, Program.
Presentation transcript:

How can you model playing rock-paper-scissors? Computer Science 1 10-22-2015 How can you model playing rock-paper-scissors?

Fix the following program just The Factorials; variables number, answer:integer; Start-O-Matic writeln('Please enter a positive integer.'); readln(nummy); factorial := 0; repeat factorial := nummy * nummy; nummy := nummy -1; until nummy := answer; writeln(' The factorial = nummy); the-bitter-end. Fix10-17Factorial

How do you model playing Rock-paper-scissors? What options do you have? How can you model each of these options?

Case statement When When you have 3 or more choices Semantics

Expression must be ordinal (integer or char) Case Syntax case expression of 5 : WriteLn('Int is 5'); 7..12,15 : WriteLn('Between 7..12 or 15'); else begin WriteLn('Undefined.'); writeln(‘Try again later’); end; {Of this choice} end;{Of the case.} Constants: if the expression resulted in a char, you would need to have character constants (Like ‘A’, ‘B’, …) Note case has no begin, but does have an end!!!

program CaseExample; var Choice:integer; begin writeln(‘Choose one of the following’); writeln(‘ 1 - Titan Burger’); writeln(‘ 2 - SwordFish Sandwich’); writeln(‘ 3 - Chicken Nuggets’); readln(choice); case choice of 1:begin writeln(‘Titan Burger $3.00’); writeln(‘Yum Yum’); end; 2: writeln(‘Swordfish $5.00’); 3: begin writeln(‘No Chicken’); writeln(‘We’’re very sorry’); end; {Of the case statement} end.

Dry run the following program casecheck; var counter:integer; begin for counter:= 1 to 9 do case counter MOD 5 of 0:write('often '); 1:write('What '); 2,4:write('is '); 3:write('not '); end; {Of the case} end; {Of the for loop} writeln; end.

Program options Planet weight Quadrant check Write a program that lets the user find their weight on any of the following planets/stars. Sun(27.94) Moon (0.17) Saturn (1.15) Mercury (0.37) Venus(0.88) Jupiter (2.64) Rock-paper-scissors against the computer (This one is tricky!) Quadrant check Input: The measure of an angle in degrees. Output: Which quadrant the angle falls into. 0<First Quadrant<90 90<Second <180 180<Third<270 270<Fourth<360 The series of quadrants starts all over again at 360. How do you handle when the angle matches an axis?