“Guess the Number”Using C
Taesoo Kwon
Heejin Park
Hanyang University
Introduction
The “Guess the Number” Game
• Simple program 1• while statements
• Simple program 2• if statements
• Simple program 3• rand()function
2
Simple program1
A Simple Example of C programming
3
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
Simple program2
5
A Simple Example of C programming
Simple program2
• Source code: if statements
A Simple Example of Dev-C++
6
Simple program3
A Simple Example of Dev-C++
7
Simple program3– Source code: rand() functions
A Simple Example of Dev-C++
8
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!
The “Guess the Number” Game with Dev-C++
Dev-C++ program “Guess the Number”
10
The “Guess the Number” Game with Dev-C++
• Python source code
• Dev-C++ source code
11
The “Guess the Number” Game with Dev-C++
• Python source code
• Dev-C++ source code
12
The “Guess the Number” Game with Dev-C++
• Python source code Dev-C++ source code
13
The “Guess the Number” Game with Dev-C++
• Python source code
• Dev-C++ source code
14
The “Guess the Number” Game with Dev-C++
• Dev-C++ source code (1/2)
15
The “Guess the Number” Game with Dev-C++
• Dev-C++ source code (2/2)
16
The “Guess the Number” Game with Dev-C++
• Dev-C++ source code – if else
17