Need help with my first program

This is a discussion on Need help with my first program within the Game Programming forums, part of the General Programming Boards category; hi everyone, im very new to programing, and i just made my first program/ game... if you could call it ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    6

    Need help with my first program

    hi everyone, im very new to programing, and i just made my first program/ game... if you could call it that...called pick a number, reeeeeaaalllyyy simple, at first it ran, then i tired to make it a lil more complicated, and now it wont run,

    can some one help me out. and tell me wwhat i didd wrong,

    here's the code


    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int thisisanumber;
        
        cout<<"hello! where going to play a game, if you win your cool... if you lose.... well then you suck Pick a number from 1-10: ";
        cin>> thisisanumber;
        cin.ignore();
        if ( thisisanumber == 36) {
             cout<<"Yo your cool, Congratz\n";
             }
             if ( thisisanumber <= 101)  {
                  cout<<"I Said 1 through 100, Try again"; // if a person types over 100
                  {
             if ( thisisanumber <= 37) {
                  cout<<" Your to High TAKE IT DOWN A NOTCH"; // is a persons answer is too high
                  }
             if ( thisisanumber >= 35) {
                  cout<<" Your To Low, go up up up."; // if a persons answer is too low
                  }
        cin.get();
    } // this is were it syad the problem is

  2. #2
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    Try this....
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int thisisanumber;
        
        cout<<"hello! where going to play a game, if you win your cool... if you lose.... well then you suck Pick a number from 1-10: ";
        cin>> thisisanumber;
        cin.ignore();
        if ( thisisanumber == 36) {
             cout<<"Yo your cool, Congratz\n";
             }
             if ( thisisanumber <= 101)  {
                  cout<<"I Said 1 through 100, Try again"; // if a person types over 100
                  {
             if ( thisisanumber <= 37) {
                  cout<<" Your to High TAKE IT DOWN A NOTCH"; // is a persons answer is too high
                  }
             if ( thisisanumber >= 35) {
                  cout<<" Your To Low, go up up up."; // if a persons answer is too low
                  }
        cin.get();
    } // this is were it syad the problem is
    }
    }

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    6
    thx... but why didn't it run becuase of that?

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,706
    Technically, it didn't compile. Anyway, any opening brace (like a curly bracket or parenthesis) needs a closing brace. You're program didn't have that initially.

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    You put an opening brace where you wanted a closing one.

    Code:
    if ( thisisanumber <= 101)  {
                  cout<<"I Said 1 through 100, Try again"; // if a person types over 100
                  {

  6. #6
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    you could make the game even more challenging, by producing a random number for the player to guess. Here is one I made for a college course ages ago:

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <ctime>	// creates a truer random number
    
    using std::cout;
    using std::endl;
    using std::cin;
    
    // driver -- main function /////////////////////////////////////////////////////
    //
    
    int main ( void )
    {
        int guess;            // player guess
        int tries = 0;	// smount of guesses
     		
       srand(time(0));	// seed number
     		
       int num = rand() % 100 + 1;	// create number between 1 and 100
     		
       do
       {
            cout << "Guess my number: ";
            cin >> guess;
    		 	
            tries++;
    		 	
           if ( guess < num )
          {
               cout << "\nTOO LOW" << endl;
          }
    		  
          if ( guess > num )
          {
              cout << "\nTOO HIGH" << endl;
          }
    			
        } while ( guess != num );
        
        cout << "\n\nWELL DONE! SPOT ON! It took " << tries << " attempts!" << endl;
    
        cin.ignore();
        getchar();
        
        return 0;
    }

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Code:
    cout<<"hello! where going to play a game, if you win your cool... if you lose.... well then you suck Pick a number from 1-10: ";
    This game cheats with 36 :P

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    6
    yeha the 1-10 thingy is a typo.

    and i wanted to make it random, but i wasn't sure how to just yet, im still kinda in the tutorial stages but i learn better if i try to put what i learn to use immediatly


    thx to all tho

  9. #9
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    If you look at my example, it shows you the basics of random number syntax

  10. #10
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,706

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21