From 5bcb1746feaadbfc044c5f0413f32348a153ee3a Mon Sep 17 00:00:00 2001 From: k0rrluna Date: Thu, 8 May 2025 20:47:54 +0300 Subject: [PATCH] chapter5 --- DeitelC/Chapter5/coinTossing.c | 20 ++++++++++++++++++++ DeitelC/Chapter5/flip.c | 6 ++++++ DeitelC/Chapter5/flip.h | 6 ++++++ DeitelC/Chapter5/guessTheNum.c | 19 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 DeitelC/Chapter5/coinTossing.c create mode 100644 DeitelC/Chapter5/flip.c create mode 100644 DeitelC/Chapter5/flip.h create mode 100644 DeitelC/Chapter5/guessTheNum.c diff --git a/DeitelC/Chapter5/coinTossing.c b/DeitelC/Chapter5/coinTossing.c new file mode 100644 index 0000000..f9eab25 --- /dev/null +++ b/DeitelC/Chapter5/coinTossing.c @@ -0,0 +1,20 @@ +#include +#include "flip.h" +#include +#include + +int main(void) { + + srand(time(NULL)); + + int heads = 0, tails = 0; + for(int i = 0; i < 100; i++){ + if(flip()) { + heads++; + } else { + tails++; + } + } + printf("%s%d%s%d\n", "Heads: ", heads, ", Tails: ", tails); + return 0; +} diff --git a/DeitelC/Chapter5/flip.c b/DeitelC/Chapter5/flip.c new file mode 100644 index 0000000..64eae3b --- /dev/null +++ b/DeitelC/Chapter5/flip.c @@ -0,0 +1,6 @@ +#include + + +int flip() { + return rand() % 2; +} diff --git a/DeitelC/Chapter5/flip.h b/DeitelC/Chapter5/flip.h new file mode 100644 index 0000000..4b94f54 --- /dev/null +++ b/DeitelC/Chapter5/flip.h @@ -0,0 +1,6 @@ +#ifndef FLIP_H +#define FLIP_H + +int flip(); + +#endif diff --git a/DeitelC/Chapter5/guessTheNum.c b/DeitelC/Chapter5/guessTheNum.c new file mode 100644 index 0000000..c6695b8 --- /dev/null +++ b/DeitelC/Chapter5/guessTheNum.c @@ -0,0 +1,19 @@ +#include +#include +#include + +int main(void) { + srand(time(NULL)); + int num = 1 + rand() % 999; + printf("%s\n%s\n%s\n", "I have a number between 1 and 1000.", "Can you guess my number?", "Please type your first guess."); + int scanNum = 0; + scanf("%d", &scanNum); + + if((scanNum > 1001) || (scanNum < 0)) { + puts("Invalid integer!"); + } + + while(scanNum != num) { + if("") + } +}