“guess the number”calab.hanyang.ac.kr/courses/isd_taesoo/c02.guess_the_number.pdf · the...

17
“Guess the Number” Using C Taesoo Kwon Heejin Park Hanyang University

Upload: others

Post on 30-Jul-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

“Guess the Number”Using C

Taesoo Kwon

Heejin Park

Hanyang University

Page 2: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

Introduction

The “Guess the Number” Game

• Simple program 1• while statements

• Simple program 2• if statements

• Simple program 3• rand()function

2

Page 3: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

Simple program1

A Simple Example of C programming

3

Page 4: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

Simple program1

• Source code: while loops

4

A Simple Example of C programming

– Here, do not use system(“PAUSE”);

– PAUSE is a non-standard command only for Windows

Page 5: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

Simple program2

5

A Simple Example of C programming

Page 6: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

Simple program2

• Source code: if statements

A Simple Example of Dev-C++

6

Page 7: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

Simple program3

A Simple Example of Dev-C++

7

Page 8: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

Simple program3– Source code: rand() functions

A Simple Example of Dev-C++

8

Page 9: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

The “Guess the Number” Game with Dev-C++

Python program “Guess the Number”

9

Hello! What is your name?AlbertWell, Albert, I am thinking of a number between 1 and 20.Take a guess.10Your guess is too high.Take a guess.2Your guess is too low.Take a guess.4Good job, Albert! You guessed my number in 3 guesses!

Page 10: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

The “Guess the Number” Game with Dev-C++

Dev-C++ program “Guess the Number”

10

Page 11: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

The “Guess the Number” Game with Dev-C++

• Python source code

• Dev-C++ source code

11

Page 12: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

The “Guess the Number” Game with Dev-C++

• Python source code

• Dev-C++ source code

12

Page 13: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

The “Guess the Number” Game with Dev-C++

• Python source code Dev-C++ source code

13

Page 14: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

The “Guess the Number” Game with Dev-C++

• Python source code

• Dev-C++ source code

14

Page 15: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

The “Guess the Number” Game with Dev-C++

• Dev-C++ source code (1/2)

15

Page 16: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

The “Guess the Number” Game with Dev-C++

• Dev-C++ source code (2/2)

16

Page 17: “Guess the Number”calab.hanyang.ac.kr/courses/ISD_taesoo/C02.Guess_the_Number.pdf · The “Guess the Number” Game with Dev-C++ Python program “Guess the Number” 9 Hello!

The “Guess the Number” Game with Dev-C++

• Dev-C++ source code – if else

17