Thread: Wanna Optimize my code?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Programmer
    Join Date
    Aug 2005
    Location
    Ohio
    Posts
    8

    Question Closing Problem!

    Hi! This is one of my first programs, and My first thread. I was wondering if anyone could tell why, after you miss the missing number twice, the rogram closes, and if there are any ways to optimize this code?
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <stdlib.h>
    #include "stdio.h"
    #include "windows.h"
    
    using namespace std;
    
    int title()
    {
    cout << "W";
    Sleep(200);
    cout<< "e";
    Sleep(200);
    cout<<"l";
    Sleep(200);
    cout<< "c";
    Sleep(200);
    cout <<"o";
    Sleep(200);
    cout <<"m";
    Sleep(200);
    cout <<"e";
    Sleep(200);
    cout <<" ";
    Sleep(200);
    cout <<"t";
    Sleep(200);
    cout <<"o";
    Sleep(200);
    cout <<" ";
    cout <<".";
    Sleep(200);
    cout << ".";
    Sleep(200);
    cout << ".";
    Sleep(2000);
    cout <<"T\n";
    Sleep(200);
    cout <<"               h\n";
    Sleep(200);
    cout <<"                e\n";
    Sleep(200);
    cout <<"                  \n";
    Sleep(200);
    cout <<"                  G\n";
    Sleep(200);
    cout <<"                   u\n";
    Sleep(200);
    cout <<"                    e\n";
    Sleep(200);
    cout <<"                     s\n";
    Sleep(200);
    cout <<"                      s\n";
    Sleep(200);
    cout <<"                       i\n";
    Sleep(200);
    cout <<"                        n\n";
    Sleep(200);
    cout <<"                         g\n";
    Sleep(200);
    cout <<"                          \n";
    Sleep(200);
    cout <<"                           G\n";
    Sleep(200);
    cout <<"                            a\n";
    Sleep(200);
    cout <<"                             m\n";
    Sleep(200);
    cout <<"                              e\n";
    Sleep(200);
    cout <<"                               !\n\n\n\n";
    Sleep (2000);
    system("cls");
    cout<< "This is a fairly hard game, so if you can win,\n";
    cout << "you're either really lucky or extrememly smart.\n\n\n\n";
    system("pause");
    system("cls");
    }
    
    int easy()                                                        
    { 
    int wingame=0;
    int answer;
        srand((unsigned)time(0));
    int random = rand();  
    int trys =15;
     
    cout << "Here we go...\n\n\n\n\n";
    
    
    do 
    { 
         
        cout << "What is your guess? -";
        cin >> answer;
        
    if (answer < random)
    { 
               
               cout << "Too Small!\n\n\n";
               trys = trys - 1;
               cout << "Only " << trys <<" trys left!\n\n";
    }
    
    if (answer > random)
    {
               cout << "Too Big!\n\n\n";
               trys = trys - 1;
               cout << "Only " << trys <<" trys left!\n\n";
    } 
    
    if (answer ==  random)
    {
               cout << "Great!\n\n\n";
               wingame = 1;
               Sleep(200);
               title();          
    }
    }
    while (wingame == 0, trys > 0);
    if (trys == 0)
    {cout <<"Sorry! You're out of trys!";
    }
    Sleep(3000);
    system("cls");
    if (wingame == 1)
    {
    title();
    }
    }
    
    int menu()
    {
        
        int level;
    cout << "^^-----**Menu**-----^^\n\n\n\n";
    
    cout << "1. Begin the Game\n";
    cout << "2. Read Instructions\n\n\n";
    // input level of user
    cout <<"What is your choice? -";
    cin >> level;
    if (level == 1)
    {
              easy();
          
    }
    if (level == 2)
    {
    cout << "This is a guessing game!(duh)\n";
    Sleep (1000);
    cout << "You have 10 trys to guess a random number,\n";
    Sleep (1000);
    cout << "which can be either huge or small.\n";
    Sleep (1000);
    cout << "When you finish, e-mail me to tell me how much you hated it!\n\n\n\n\n\n\n\n\n";
    system ("PAUSE");
    system("cls");
    }
    easy();
    }  
    
    int main()
    {
    
    title();
    menu();
    
       
    system("PAUSE");
    return EXIT_SUCCESS;
    
    }
    Last edited by Echo; 08-14-2005 at 05:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  4. wanna read some code
    By snakattak in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 06-19-2002, 04:21 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM