URI:
   DIR Return Create A Forum - Home
       ---------------------------------------------------------
       The New DS computer forum!!
  HTML https://dscomp.createaforum.com
       ---------------------------------------------------------
       *****************************************************
   DIR Return to: C++
       *****************************************************
       #Post#: 302--------------------------------------------------
       Tutorial #6 - Your first proper game. Lost Fortune. Part 2
       By: Hondaman Date: October 22, 2010, 10:02 am
       ---------------------------------------------------------
       [center]Welcome to Tutorial No. 6 (part 2)
       In this tutorial you will putting everything you have learned
       so-far into a game.[b][/center]
       [font=trebuchet ms][b]Getting the users information -[/font]
       In the last tutorial you setup and introduced the game...
       In this tutorial you will be getting ht users information.
       The information you will need is -
       - A Random Number
       - A Random Number Smaller Than The First
       - The Users Last Name
       so this means there will be 6 lines of code we need to write.
       These lines will be,
       [code]
       Cout << The Question << endl;
       Cin >> The variable.
       [/code]
       For each question.
       and if you can't remember the variables they were
       GOLD_PIECES
       adventurers
       killed
       survivors
       leader
       What I would like you to do is try to guess the lines of code
       and work it out for yourself...
       Then check it with the below code...
       This will help you check your coding skills so-far and also see
       how well you matched up the questions and variables.
       So if you haven't done that don't look at the code below.
       [code]
       #include <iostream>
       #include <string>
       using namespace std;
       
       int main()
       {
       const int GOLD_PIECES = 900;
       int adventurers, killed, survivors;
       string leader;
       
       // Introducing the game
       
       cout << "\tWelcome to Lost Fortune." << endl;
       cout << "\tPlease enter some of your information for the
       story.\v"
       
       // Getting the users information
       
       cout << "Please enter a random number" << endl;
       cin >> adventurers;
       
       cout << "Please enter a smaller number" << endl;
       cin >> killed;
       
       cout << "Please enter you'r last name" << endl;
       cin >> leader;
       }
       [/code]
       And finally working out out last variable.
       'Survivors'
       
       But to do this, we need to learn a quick few things about maths.
       Don't worry! you don't need a calculator or be good at maths to
       do this.
       Here are some basic maths functions.
       Name                 Sign               Function
       [list]
       [li]Addition       -      '+'         -        Adds two numbers
       together[/li]
       [li]Takeaway    -      '-'         -        Subtracts two
       numbers.[/li]
       [li]Divide          -       '/'         -        Divides a
       number from another number.[/li]
       [li]Times           -      '*'         -        Multiply's two
       numbers.[/li]
       [li]Modulo        -       '%'       -         Calcualtes the
       remainder after dividing two numbers. e.g. 11 % 3 would equal
       2[/li]
       [/list]
       So to work out the number of survivors,
       We would need to do the following line of code.
       [code]
       survivors = adventurers - killed;
       [/code]
       So now that we have that done...
       We should have the following block of code.
       [code]
       #include <iostream>
       #include <string>
       using namespace std;
       
       int main()
       {
       const int GOLD_PIECES = 900;
       int adventurers, killed, survivors;
       string leader;
       
       // Introducing the game
       
       cout << "\tWelcome to Lost Fortune." << endl;
       cout << "\tPlease enter some of your information for the
       story.\v"
       
       // Getting the users information
       
       cout << "Please enter a random number" << endl;
       cin >> adventurers;
       
       cout << "Please enter a smaller number" << endl;
       cin >> killed;
       
       cout << "Please enter you'r last name" << endl;
       cin >> leader;
       
       survivors = adventurers - killed;
       }
       [/code]
       In part 3 you will be writing the story and that will be us
       done.
       You will then have finally compleated your first miniture game.
       Thanks for reading this tutorial. please check out part 3.
       If you see any mistakes or problems with my tutorials please PM
       me.
       Hondaman.
       
       [center]<< Previous
  HTML http://www.dscompforums.tk/c/tutorial-6-your-first-proper-game-lost-fortune-part-1/<br
       />  |   Next >>
  HTML http://www.dscompforums.tk/c/tutorial-6-your-first-proper-game-lost-fortune-part-3/[/center]
       *****************************************************