Last active
January 31, 2023 11:03
-
-
Save Dalmanski/d2691558f9ff4f5fdfd07ad4c6e76aa9 to your computer and use it in GitHub Desktop.
Magic Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> // Header starter. | |
#include <stdlib.h> // for system ("cls"); | |
#include <cstdio> // for fflush(stdin); clear the scanf. | |
void border() | |
{ | |
printf("\n\n\t <===================================>\n"); | |
} | |
void magicnumbertext() | |
{ | |
printf("\n\t $$ $$ $$$$$$ $$$$$$ $$$$$$ $$$$$$"); | |
printf("\n\t $ $ $ $ $$ $$ $$ $$ $$ "); | |
printf("\n\t $ $ $ $$$$$$ $$ $$$ $$ $$ "); | |
printf("\n\t $ $ $$ $$ $$ $$ $$ $$ "); | |
printf("\n\t $ $ $$ $$ $$$$$$ $$$$$$ $$$$$$"); | |
printf("\n"); | |
printf("\n\t $ $ $ $ $ $ $$$ $$$ $$$ "); | |
printf("\n\t $$ $ $ $ $$ $$ $ $ $ $ $"); | |
printf("\n\t $ $ $ $ $ $ $ $ $$$ $$$ $$$ "); | |
printf("\n\t $ $$ $ $ $ $ $ $ $ $ $ "); | |
printf("\n\t $ $ $$$$ $ $ $$$ $$$ $ $"); | |
printf("\n"); | |
} | |
void logo() | |
{ | |
printf("\n\t\t @@@@@@@ "); | |
printf("\n\t\t @ @ @ "); | |
printf("\n\t\t @ @ "); | |
printf("\n\t\t @ @ @ "); | |
printf("\n\t\t @@@ @@ "); | |
printf("\n"); | |
} | |
int findCount(int n) | |
{ | |
int count = 0; | |
while (n != 0) | |
{ | |
count++; | |
n /= 10; | |
} | |
return count; | |
} | |
int main() | |
{ | |
start: | |
system("cls"); | |
int num = 0, ques = 0, rep = 0, rep2 = 0, rep3 = 0; | |
int space = 0, space2 = 0, rep_ans = 0, column = 0, inp_num = 0; | |
int geoseq = 1, last_num = 1; | |
char input, enter; | |
fflush(stdin); | |
border(); | |
printf("\n\n\tBefore you start, let's set this up.\n "); | |
printf("\n\tPick a number from 1 to...?\n "); | |
printf("\n\t(Warning: The more number you input, the more \n\t about how many times you answer by yes or no.)\n"); | |
printf("\n\t(Example: Your input is 30, so you need to \n\t answer 5 times by yes or no.)\n"); | |
printf("\n\t(If you don't know, just input 0,1 or any letter)\n"); | |
border(); | |
printf("\n\tInput: "); | |
scanf("%d", &inp_num); | |
for (rep = 0; last_num <= inp_num; rep++) | |
{ | |
last_num *= 2; | |
++rep_ans; | |
} | |
last_num -= 1; | |
fflush(stdin); | |
if (inp_num > 1) | |
{ | |
printf("\n\t> If you want to choose from 1 to %d, input 'y'.", inp_num); | |
if (inp_num != last_num) | |
{ | |
printf("\n\t> If you want to extend from 1 to %d, input 'e'.", last_num); | |
} | |
printf("\n\t> If you want to change, input 'c' or any."); | |
border(); | |
printf("\n\tInput: "); | |
scanf("%c", &input); | |
if (input == 'y') | |
{ | |
last_num = inp_num; | |
} | |
else if (input != 'y' && input != 'e') | |
{ | |
goto start; | |
} | |
} | |
system("cls"); | |
fflush(stdin); | |
border(); | |
if (inp_num <= 1) | |
{ | |
printf("\n\tAlright, I'll automatically choose from default. \n"); | |
last_num = 31; | |
rep_ans = 5; | |
} | |
printf("\n\t\t\tWelcome to\n"); | |
magicnumbertext(); | |
printf("\n\t\t Made by Dalmanski\n"); | |
logo(); | |
printf("\n\t\t Press Enter to Continue."); | |
border(); | |
fflush(stdin); | |
scanf("%c", &enter); | |
system("cls"); | |
border(); | |
printf("\n\t(Pick any number on your mind between 1 to %d.)\n", last_num); | |
printf("\n\tIf your done, \n\tPress Enter to Continue."); | |
printf("\n\t(Don't input your number)"); | |
border(); | |
fflush(stdin); | |
scanf("%c", &enter); | |
do | |
{ | |
system("cls"); | |
fflush(stdin); | |
border(); | |
if (enter != '\n' && ques == 0) | |
{ | |
printf("\n\t I told you to press Enter. \n "); | |
printf("\n\t Anyway... \n "); | |
} | |
++ques; | |
rep2 = geoseq; | |
rep3 = 0; | |
column = 0; | |
if (input != 'y' && input != 'n' && ques != 1) | |
{ | |
printf("\n\t Your input is not yes or no so"); | |
printf("\n\t I'll automatically say no to that."); | |
printf("\n\n\t If my automatically no is not your answer,"); | |
printf("\n\t type 'try again' or type 'yes' next time.\n"); | |
} | |
if (ques == 1) | |
{ | |
printf("\n\t You need to answer %d times. \n", rep_ans); | |
} | |
printf("\n\t %d/%d) Find your number.\n", ques, rep_ans); | |
while (rep3 <= (last_num + 1) / 2 && rep2 <= last_num) | |
{ | |
for (rep = 0; rep < geoseq && rep2 <= last_num; rep++) | |
{ | |
if (column == 0) | |
{ | |
printf("\n"); | |
for (space2 = 0; space2 < 17 - findCount(last_num); space2++) | |
{ | |
printf(" "); | |
} | |
} | |
for (space = 0; space < findCount(last_num) - findCount(rep2); space++) | |
{ | |
printf(" "); | |
} | |
printf("%d ", rep2); | |
rep2++; | |
rep3++; | |
column++; | |
if (column == 4 && last_num < 50 || column == 11 - findCount(last_num)) | |
{ | |
column = 0; | |
} | |
} | |
rep2 += geoseq; | |
} | |
printf("\n\n\t Is your number here? yes or no? "); | |
border(); | |
printf("\n\t Input: "); | |
scanf("%c", &input); | |
if (input == 'y') | |
{ | |
num += geoseq; | |
} | |
else if (input == 't') | |
{ | |
goto start; | |
} | |
geoseq *= 2; | |
printf("\n\t "); | |
} while (ques < rep_ans); | |
system("cls"); | |
border(); | |
if (num != 0) | |
{ | |
if (num <= last_num) | |
{ | |
printf("\n\n\t\t Your number is\n"); | |
printf("\n\t\t\t %d\n", num); | |
printf("\n\t\t Thank you! \n"); | |
printf("\n\n\t If this number is not your number,"); | |
printf("\n\t make sure you check it properly."); | |
printf("\n\t I checked it and it got my number right. \n"); | |
printf("\n\t\t Press Enter to Try Again."); | |
} | |
else | |
{ | |
printf("\n\n\t\t Your number is beyond %d \n", last_num); | |
printf("\t but the number is not there. \n"); | |
printf("\n\t\t\tTry again. \n"); | |
printf("\n\t\t Press Enter to Try Again.\n"); | |
} | |
} | |
else | |
{ | |
printf("\n\n\t\tYour number is not in 1 to %d. \n", last_num); | |
printf("\n\t\t\t Try again. \n"); | |
printf("\n\t\t Press Enter to Try Again.\n"); | |
} | |
border(); | |
fflush(stdin); | |
scanf("%c", &enter); | |
goto start; | |
} | |
// Released in January,28,2023. | |
// Update: | |
// 01/28/23: | |
// > New interaction that automatically chooses a number from 1 to 31 if your input is 0 or a letter. | |
// > If you do not press enter after the introduction, it will say "I told you to press Enter." | |
// > If your answer is not 'yes' or 'no,' it will automatically be interpreted as 'no'. | |
// > You can try again by inputting 't' while answering yes or no. | |
// 01/29/23: | |
// > Reformatted, correcting grammatical errors and adjusting tabs. | |
// > Added a function to determine the number of digits. | |
// > Replaced the use of \t with a for loop for adding spacing based on the number of digits in the last number. | |
// > Changed the introduction set-up from repeating yes or no to choosing a number from 1 to...? | |
// 01/30/23: | |
// > Reformatted, Like changing "rep2 = geoseq + rep2" to "rep2 += geoseq." | |
// > Adjusted the column of the number generation based on the number of digits in the last number. | |
// > Added a header #include<cstdio> for fflush(stdin), which only works on C compilers like DevC++ and CxxDroid. Other C compilers, especially online C compilers, may not work. | |
// 01/31/23: | |
// > Added a system to ask if you would like to extend the range or change it. For example, if you input 28, it will ask if you want to extend it to 1 to 31 or keep it 1 to 28 or change it. | |
// > Added an end text if your answer to 'yes' or 'no' is not found on the number, then the number detected is above the current number. | |
// > Adjusted the 4 columns again for numbers 31 and below. | |
// Some updates have not been announced yet. You can view my revisions on Github Gist. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need Devc++ for PC and Cxxdroid for Android to run. Idk if other c compiler work.