Page 1 of 1

my second C++ program

Posted: Mon Nov 22, 2010 6:41 pm
by PinPoint
thought id post this one also. just finished it, little number guessing game. still going to do more like add option to give up and clues etc but im proud of this nonetheless even if noone else is :)

Code: Select all

/* This is my second ever program made by memory and trial and error.
Created by PinPoint on 22/11/2010 after a few hours learning C++ */

#include <iostream>
#include <cstdio>
using namespace std;

int main ()
{
    
    int number;
    int guess;
        
    number = (423);
    
    cout << "Press enter to Play My Game...\n";
         getchar();
    cout << "Guess the number equal to or higher\n"
         << "than 0 and equal to or smaller than\n"
         << "1000 and you will get a surprise\n\n";
                cout << "I think the number is = "; 
         cin >> guess;
             getchar();

restart1:  
               
               
                        
if (guess==number) 
{
   cout << "\n\nYOU'RE AWSOME!!!!!\n\n";
        getchar();
        cout <<"Goodbye and thanks for playing.\n";
}
                                   
else if (guess<number) 
{  
   cout << "\n\nYou're guess is lower\n\n\tI think the number is = ";
        cin >> guess;
        
        goto restart1;
            getchar();
}
else if (guess>number)
{
   cout << "\n\nYou're guess is higher\n\n\tI think the number is = ";
        cin >> guess;
        goto restart1;
            getchar();
}
    getchar();    
    return 0;
}

the game is attached for you all to try also

Re: my second C++ program

Posted: Mon Nov 22, 2010 8:16 pm
by Sethioz
now make it randomize the number, so its never same.

Re: my second C++ program

Posted: Mon Nov 22, 2010 8:56 pm
by PinPoint
just need to change number = (423); to number (rand());