Thread: The Magic Gopher - New beginners programming challenge

  1. #16
    Registered User
    Join Date
    Aug 2011
    Posts
    91
    hey Im not able to send pms? so I am pasting it here.

  2. #17
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    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...");
                    System.Threading.Thread.Sleep(3000);
                    Console.WriteLine("...{0}!", magicWord);
    
                    FlushInputBuffer();
                    Console.Write("{0}Play again (y/N)? ", Environment.NewLine);
                    playAgain = Console.ReadLine();
                } while (playAgain.Length > 0 && Char.ToLower(playAgain[0]) == 'y');
            }
    
            static void Pause()
            {
                FlushInputBuffer();
                Console.Write("{0}Press any key to continue...", Environment.NewLine);
                Console.ReadKey(true);
                Console.Clear();
            }
    
            static void FlushInputBuffer()
            {
                while (Console.KeyAvailable)
                    Console.ReadKey(true);
            }
    
            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!
    If you understand what you're doing, you're not learning anything.

  3. #18
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    @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.
    Last edited by rogster001; 09-23-2012 at 08:55 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  4. #19
    Registered User
    Join Date
    Aug 2011
    Posts
    91
    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";
    	cout<<"\n\t\t\tSIT STILL AS I READ YOUR MIND\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;
    }
    }
    Last edited by theju112; 09-23-2012 at 10:19 AM.

  5. #20
    Registered User
    Join Date
    Aug 2011
    Posts
    91
    Quote Originally Posted by rogster001 View Post
    @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. #21
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    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;
    }
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++/C Beginners Codebreak challenge
    By rogster001 in forum Contests Board
    Replies: 55
    Last Post: 03-11-2010, 06:59 AM
  2. Beginners C Programming Challenge
    By UCnLA in forum C Programming
    Replies: 23
    Last Post: 04-01-2008, 07:46 PM
  3. Beginners C Programming Challenge
    By UCnLA in forum C Programming
    Replies: 2
    Last Post: 03-18-2008, 12:15 PM
  4. What ever happened to gopher?
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 06-01-2004, 07:06 PM
  5. C programming challenge
    By lost in C in forum C Programming
    Replies: 6
    Last Post: 03-11-2002, 01:27 AM