Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

Studies

משחק ניחושים

יש לנו כעת מספיק כלים בשביל לבנות תוכנית קצרה ופשוטה אבל שעדיין עושה משהו מעניין. נבנה משחק ניחוש - נבחר מספר סודי, והמשתמש ינסה לנחש אותו. אם הוא לא יצליח, נגיד לו האם היה קטן/גדול מהמספר הסודי כדי שיוכל לשפר את הניחוש הבא שלו.

#include <stdio.h>
int main() {
    int secret = 9;
    int guess;
    printf("Enter a guess for the secret number!\n");
    scanf("%d", &guess);
    if (guess == secret) {
        printf("You win - secret was %d!\n", secret);
    } else if (guess < secret) {
        printf("Your guess is smaller than secret!\n");
    } else if (guess > secret) {
        printf("Your guess is bigger than secret!\n");
    }
}