Inferno Web Development
  • Home
  • Forums
  • About
  • Links
  • Contact

Tutorials List

  • C++ Tutorials

Articles

  • Java
  • PHP
  • Photoshop
  • C#
  • C++ Qt GUI
  • C++ Win32 API
  • C++
  • MASM32
  • General News
  • JavaScript
  • Web Development
  • Windows Tweaks

Popular Tutorials

All time:

  • Website Header with 3D Fold Up / Lift Effect
  • C++ Win32 API Tutorial
  • Perfect C++ String Explode Split
  • Simple C++ DLL Loading a Message Box
  • Simple C++ Pointers and References

Related Articles

  • C++ Pthreads API
  • Beginner C++ Cout Cin Integer
  • Singleton C++
  • C++ Volatile Keyword
  • Perfect C++ String Explode Split

Programming Tutorials

Home

C++ Beginner Programming Video Tutorial

Submitted by Baran Ornarli on Thu, 11/13/2008 - 06:39.
  • C++

In this video, we make a simple guessing game for beginners using C++ and we also explain how to set up your programming environment. This is a very simple tutorial for beginners.

Now if you want to improve your C++ skills, you should try and use a while(1) or infinite loop around your code so that the game restarts when the user loses or wins the guessing game. If you are able to modify your code, well just post your code on InfernoDevelopment Programming Forums and show off your C++ skills so that others can learn.

If you want to see the finished program:

#include <cstdlib>
#include <iostream>
// The two slashes are comments
// this text will not be compiled
// the above 2 #include statements
// are to bring in 2 standard
// libraries from the C++ libraries
// the first one is for system()
// which is a function.
// The second one is for cout, cin
// which is output to the screen
// and input from the user keyboard
using namespace std;
// if we don't put up the above
// using statement. Then we would
// be forced to write cout and cin
// like this: std::cout or std::cin
// so we're just saying we want to
// always use std for cout/cin.
 
 
 
// int main is simply the standard
// function for all beginning 
// C++ programs.
// the int means integer, because
// when function main is finished
// it will return an integer type.
int main(int argc, char *argv[])
{
    int guess(0); 
    // we just initialized a 
    // local variable called
    // guess. C++ is case sensitive.
    // guess is initialized as 0.
    // this is the same as
    // int guess = 0;
    // this will be our guessing number.
    int MyGuess(0);
    // this is another integer at zero.
 
    srand(time(NULL));
    // srand is a function that
    // seeds the rand() function
    // with a time(0) (UNIX time),
    // basically it will
    // generate an almost random 
    // starting point for rand().
    guess = rand()%10+1;
    // this will be the number we have to guess
    // The %10 means 10 is maximum random number.
    // The +1 means 1 is the minimum random
    // number.
    // Now guess contains our random number.
    // % is actually modulus (divide by 10, get
    // remainder).
 
    cout << "Guess our random number (1-100)\n";
    // cout will output text to our console.
    // pay attention to the arrows facing cout.
    // We add our string that we want to print.
    // \n means a new line should appear there.
    // it's like pressing return/enter on keyboard.
 
    cin >> MyGuess;
    // This will wait for the user to type
    // a number to the screen. It will save it
    // as MyGuess. A space or return/enter
    // will make the code continue.
    cout << "You guessed " << MyGuess << ", the answer";
    cout << " was " << guess << "\n";
    // We tell the user the results.
    if(MyGuess == guess){ // check if MyGuess is guess
       cout << "You guessed it!\n";
    } else { // otherwise
       cout << "You failed this extremely simple game.\n";
    }
 
 
    system("PAUSE");
    // This will pause the program.
    // displaying a message like
    // "Press any key to continue".
    // which will end program.
    return EXIT_SUCCESS;
    // exit success is just a
    // representation for integer zero.
}


5
Average: 5 (1 vote)
»
  • Share Tutorial

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <img> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h4> <h2>
  • Lines and paragraphs break automatically.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • You can use BBCode tags in the text. URLs will automatically be converted to links.
  • Table of contents based on the <h*> tags

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
   .o                     .o     oooooooooooo                 oooooooo 
o888 .d88 d'""""""d888' dP"""""""
888 .ooooo oo .d'888 .888P oooo oooo d88888b.
888 d88' `888 .d' 888 d888' `888 `888 `Y88b
888 888 888 88ooo888oo .888P 888 888 ]88
888 888 888 888 d888' .P 888 888 o. .88P
o888o `V8bod888 o888o .8888888888P `V88V"V8P' `8bd88P'
888.
8P'
"
Enter the code depicted in ASCII art style.

Navigation

  • Home
  • Forums
  • Image Gallery
  • Links
  • About
  • Contact

Why Register? Contribute articles and tutorials to ID, earn titles, learn from ID programming projects, and advertise your blog in our forums.

  • Forum Community
  • Register Now
  • Write an Article


Copyright © Inferno Development 2008-2009. All Rights Reserved.