my second C++ program

c, c++, php, html, sql ..etc discussion. also includes codes and source codes.

my second C++ program

Postby PinPoint » Mon Nov 22, 2010 6:41 pm

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
Attachments
guess the number game.rar
(104.71 KiB) Downloaded 154 times
Last edited by PinPoint on Mon Nov 22, 2010 8:57 pm, edited 1 time in total.
User avatar
PinPoint
Special
Special
 
Posts: 128
Joined: Wed Dec 03, 2008 6:41 pm

Re: my second C++ program

Postby Sethioz » Mon Nov 22, 2010 8:16 pm

now make it randomize the number, so its never same.
User avatar
Sethioz
Admin
Admin
 
Posts: 4754
Joined: Fri Jul 27, 2007 5:11 pm
Location: unknown

Re: my second C++ program

Postby PinPoint » Mon Nov 22, 2010 8:56 pm

just need to change number = (423); to number (rand());
User avatar
PinPoint
Special
Special
 
Posts: 128
Joined: Wed Dec 03, 2008 6:41 pm


Return to Programming / Coding / Debugging

Who is online

Users browsing this forum: No registered users and 2 guests

cron