Simple Number Guess Program

D

Dan-Kode

Guest
So I just installed Linux Ubuntu(Mainly for Programming) and when I did, I wrote a simple Program in C to just test out compiling my Code and also just for the fun of it. That was yesterday(UK Time) when I installed Linux Ubuntu and wrote that Program. As of today(UK Time), I re-wrote the Program.

It's a simple Program. All you need to do is just guess the Number that the Computer is thinking of and then depending on what you guess, you'll either get it right or wrong.

Here is the Source-Code:
number.c:
#include <stdio.h>

int main(void) {
    int usr_num = 0; // The Number that the User inserts
    int app_num = 56; // The Number that the Program is thinking of

    // Welcome Message
    printf("Hey. I'm thinking of a Number. Try and guess it and I'll tell you if you're right: ");
    // Receive Input for the Number
    scanf("%d", &usr_num);
   
    // Determine if the User got it right
    if(usr_num == app_num) {
        // Print this if they got it right
        printf("Yay! You got it right!\n");
    } else {
        // Print this if they got it wrong
        printf("Sorry. That wasn't right. The Answer was: 56\n");
    }
   
    return 0;
}
If you want to test it out for yourself then feel free to do so. But if you do then I suggest doing it in a UNIX-Environment(Preferably inside a Linux Distro as that was what the Code was compiled and tested on). You can do it on another UNIX-Environment such as MacOS X but I'm not sure if it does have the same Commands used in the Terminal to Compile and Test the Program. If you want to test on Windows then I'm not sure what you're going to need to run it(You'll probably have to go through the pain that is MinGW).

Yet again, feel free to test it out for yourself.

You can get the Program here: https://codeforum.org/resources/simple-number-guessing-program.22/
 
Last edited by a moderator:
  • Like
Reactions: Malcolm
D

Dan-Kode

Guest
Well, at least you don't have to go through installing MinGW :|

And no, this wasn't my first C Program. I have made similar Programs but this was just one to try out C on Linux.
 
  • Like
Reactions: Malcolm