# Thread: The Magic Gopher - New beginners programming challenge

1. hey Im not able to send pms? so I am pasting it here.

2. Here was my entry:

Code:
```using System;
using System.Linq;
using System.Text;

namespace MagicGopher
{
class Program
{
static void Main(string[] args)
{
string playAgain;

do
{
Console.Clear();

Console.WriteLine("Greetings! I possess the power to read one's thoughts. Allow me to demonstrate. Think of a 2-digit number (i.e., a number between 10 and 99).");
Pause();

Console.WriteLine("Now take each of the digits in your number and add them together. For instance, if your number is 39, you'd do 3 + 9 = 12.");
Pause();

Console.WriteLine("Now take your original number and subtract the number you just got from it (e.g., 39 - 12 = 27).");
Pause();

Console.WriteLine("Now look at the chart below. Find the word next to the number you just calculated and remember it.{0}", Environment.NewLine);
string magicWord = ShowChart();
Pause();

Console.WriteLine("I bet the word was...");
Console.WriteLine("...{0}!", magicWord);

FlushInputBuffer();
Console.Write("{0}Play again (y/N)? ", Environment.NewLine);
} while (playAgain.Length > 0 && Char.ToLower(playAgain[0]) == 'y');
}

static void Pause()
{
FlushInputBuffer();
Console.Write("{0}Press any key to continue...", Environment.NewLine);
Console.Clear();
}

static void FlushInputBuffer()
{
while (Console.KeyAvailable)
}

static string ShowChart()
{
string[] words = { "zapple", "zoing", "bzzzrr", "fwoopy", "howrk", "starp", "pling", "whirf", "proink", "snazzle", "shoif" };
Random random = new Random();

int magicWordIndex = random.Next(words.Length);
int longestWordLength = words.Max(w => w.Length);
int columnWidth = longestWordLength + 5;

for (int i = 1; i <= 96; )
{
StringBuilder sb = new StringBuilder();
for (int c = 0; c < 80 - columnWidth && i <= 96; c += columnWidth, ++i)
sb.AppendFormat(String.Format("{0,2} {{0,{1}}}", i, -(columnWidth - 3)), i % 9 == 0 ? words[magicWordIndex] : words[random.Next(words.Length)]);
Console.WriteLine(sb.ToString());
}
Console.WriteLine();

return words[magicWordIndex];
}
}
}```
Thanks again for putting this contest together!

3. @theju112 - Nice to see your entry - had a bit of a problem compiling it - had to alter some things, perhaps some feedback from other members would help, issues with headers - non standard styley stuff - but then as was pointed out this was calling for non standard. - but still i can see you have put a lot of work in there, its a good effort, - plus nice 'user taunting' in your instruction messages! cheers.

4. This is a slightly enhanced version of my previous code..just added a few more spook effects that's all
Code:
```#include <iostream.h>
#include <stdlib.h>
#include<conio.c>
#include<stdio.h>
int main()

{
while(1)
{
int j=1,temp,i,print_complete,delay=0;
char choice;
char multiple_9= (rand()%20)+14;
//cout<<multiple_9;

cout<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<"********************************************************************************";
cout<<endl<<endl<<endl<<"================================================================================";
cout<<endl<<endl<<endl<<"\t"<<"@@@@@@  YOU HAVE ENTERED THE GATES OF THE MATH GENIE  !!!!  @@@@@";
cout<<endl<<endl<<endl<<"\t\t"<<"!!!!!! GET READY TO BE MESMERIZED !!!!!!";
cout<<endl<<endl<<endl<<"================================================================================";
cout<<endl<<endl<<"\t\t   PRESS ENTER IF YOU DARE TO CONTINUE";
cout<<endl<<"********************************************************************************";
cin.get();
clrscr();
cout<<"\n\n\n\n\n\n\n\n\n";
cout<<endl<<"********************************************************************************";
cout<<endl<<endl<<endl<<endl<<endl<<endl<<"\t        THINK OF A NUMBER WITH TWO DIGITS (FOR EXAMPLE 43)";
cout<<endl<<endl<<endl<<"\t\t\t    PRESS ENTER TO CONTINUE";
cout<<endl<<"********************************************************************************";
cin.get();
clrscr();
cout<<"\n\n\n\n\n\n\n\n\n";
cout<<endl<<"********************************************************************************";
cout<<"\n\n\nNOW ADD THE TWO DIGITS OF THE NUMBER(EXAMPLE: 4+3=7)";
cout<<endl<<"********************************************************************************";
cout<<endl<<endl<<endl<<"\t\t\t    PRESS ENTER TO CONTINUE";
cin.get();
clrscr();
cout<<"\n\n\n\n\n\n\n\n\n";
cout<<endl<<"********************************************************************************";
cout<<"\n\n\nNOW SUBTRACT THE NEW NUMBER FROM YOUR ORIGINAL NUMBER(EXAMPLE: 43-7=36)";
cout<<endl<<"********************************************************************************";
cout<<endl<<endl<<endl<<"\t\t\t    PRESS ENTER TO CONTINUE";
cin.get();
clrscr();
cout<<"\n\n\n\n\n\n\n\n\n";
cout<<endl<<"********************************************************************************";
cout<<"\n\nFINALLY LOOK AT THE SYMBOL NEXT TO YOUR NUMBER AND REMEMBER IT";
cout<<endl<<"********************************************************************************";
cout<<endl<<endl<<endl<<"\t\t\t    PRESS ENTER TO CONTINUE";
cin.get();
clrscr();
cout<<endl<<endl<<endl;

for(i=95;i>=0;i--)
{print_complete=0;
temp=i;
j=1;
while(j<10)
{
if(temp>=0)
{

cout<<temp<<" ";
if((temp%9)==0)
cout<<multiple_9<<" ";
else
cout<<(char)((rand()%10)+14)<<" ";
}
if(temp==8)
{
print_complete=1;
break;
}
temp=temp-11;
j++;
}
if(print_complete==1)
{

break;
}
cout<<endl<<endl;
}
cout<<"\n\n\nPRESS ENTER TO CONTINUE";
cin.get();
clrscr();
cout<<endl<<endl<<endl<<"\n\n\n\t\t\t";
while(delay<25)
{
for(int i=0;i<8000;i++)
{
for(int i=0;i<9000;i++);
for(int i=0;i<9000;i++);

}

if(delay<4)
cout<<char(30);
if(delay>4&&delay<9)
cout<<char(24);
if(delay>9&&delay<14)
cout<<char(25);
if(delay>14&&delay<19)
cout<<char(27);
if(delay>19&&delay<24)
cout<<char(26);
delay++;

}
cout<<endl<<"********************************************************************************";
cout<<"\n\n\t\t\tMIND READING COMPLETE...\n\n\t\t\tPRESS ENTER TO CONTINUE";
cout<<endl<<"********************************************************************************";
cin.get();
clrscr();
cout<<"\n\n\n\n\n\n\n";
cout<<endl<<"********************************************************************************";
cout<<endl<<endl<<"\t\t\tTHE SYMBOL YOU REMEMBERD IS :"<<multiple_9;
cout<<endl<<"********************************************************************************";
cin.get();

clrscr();
cout<<"\n\n\n";
cout<<endl<<"********************************************************************************";
cout<<endl<<endl<<endl<<"\t\t\tDARE TO TRY AGAIN???? IF NO,PRESS N"<<endl;
cout<<endl<<"********************************************************************************";
cin>>choice;

if(choice=='n'||choice=='N')
break;
}
}```

5. Originally Posted by rogster001
@theju112 - Nice to see your entry - had a bit of a problem compiling it - had to alter some things
I guess the problem was at #include<conio.c> I started using a new compiler : c free standard(developed by programarts.com) recently.

so when i used #include<conio.h> and clrscr(), i was getting the undefined function error..

so i checked the include folder and found out that the clrscr() function was in the conio.c and it was not in the conio.h file..

6. Version 1:
Code:
```#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MAXSYM 20
#define OUTCOL 13
unsigned char symbols[MAXSYM] = {   128, 135, 143, 145, 156,
157, 158, 159, 167, 233,
224, 225, 228, 230, 231,
232, 234, 236, 237, 247,
};

unsigned char theList[100];

int main()
{
int i;
int j;
int rnd;
char sym;

srand(time(NULL));

rnd = rand() % MAXSYM;
sym = symbols[rnd];

for (i=0; i<100; i++) theList[i] = symbols[rand() % MAXSYM];
for (i=9; i<90; i+=9) theList[i] = sym;

puts(" ");
puts(" ");
puts("        Think of a 2-digit number.                      ");
puts("        Add the two digits together.                    ");
puts("        Subtract this number from the original number.  ");
puts("        Check the list below for this newest number.    ");
puts("        Concentrate on the symbol next to the number.   ");
puts(" ");
puts(" ");
for (i=0; i<OUTCOL; i++)
{
for (j=0; j<100-OUTCOL; j+=OUTCOL)
{
printf("    %2d: %c ", i+j, theList[i+j]);
}
putchar('\n');
}
puts  (" ");
puts  (" ");
printf("        When you're sick of concentrating, Press ENTER: ");
getchar();

puts  (" ");
printf("        Your symbol is  %c  \n", sym);

return 0;
}```
Version 2:
Code:
```#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

#define MAXSYM 20
#define OUTCOL 13
unsigned char symbols[MAXSYM] = {   128, 135, 143, 145, 156,
157, 158, 159, 167, 233,
224, 225, 228, 230, 231,
232, 234, 236, 237, 247,
};

unsigned char theList[100];

int main()
{
int i;
int j;
int rnd;
char sym;

srand(time(NULL));

rnd = rand() % MAXSYM;
sym = symbols[rnd];

for (i=0; i<100; i++) theList[i] = symbols[rand() % MAXSYM];
for (i=9; i<90; i+=9) theList[i] = sym;

puts(" ");
printf("\n        Think of a 2-digit number.                      ");   getch();
printf("\r        Add the two digits together.                    ");   getch();
printf("\r        Subtract this number from the original number.  ");   getch();
printf("\r        Check the list below for this newest number.    ");
puts(" ");
puts(" ");
for (i=0; i<OUTCOL; i++)
{
for (j=0; j<100-OUTCOL; j+=OUTCOL)
{
printf("    %2d: %c ", i+j, theList[i+j]);
}
putchar('\n');
}
puts("\n        Concentrate on the symbol next to the number.   \n");
printf("        When you're sick of concentrating, Press ENTER: ");
getchar();

puts  (" ");
printf("        Your symbol is  %c  \n", sym);

return 0;
}```