954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to make a C++ game??

Ok, im not that much of a geeky smart guy in C++,
but i've got some skillz..
so im trying to make a very simple game that will randomize
1 number for the computer and 1 number for the person using the program and whomever(person or computer) gets the highest number(lets say 1-10) wins, and keeps score also...
If anyone can just post here, or help me make this program in anyway that would be awsome!!!

lotsofsloths
Light Poster
44 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

First of all, I suggest taking a look at the short tutorial on random numbers here - http://www.daniweb.com/tutorials/tutorial1769.html

Bench
Posting Pro
577 posts since Feb 2006
Reputation Points: 307
Solved Threads: 63
 

As for keeping score, you could have two variables.

int games_won_by_computer;
int games_won_by_player;


Once you're done that game, you could try a guessing game where the user guesses a random number in as few tries as possible.

dwks
Posting Whiz in Training
269 posts since Nov 2005
Reputation Points: 185
Solved Threads: 28
 
Ok, im not that much of a geeky smart guy in C++, but i've got some skillz.. so im trying to make a very simple game that will randomize 1 number for the computer and 1 number for the person using the program and whomever(person or computer) gets the highest number(lets say 1-10) wins, and keeps score also... If anyone can just post here, or help me make this program in anyway that would be awsome!!!


its very simple
wat exactly u want ?
source code ??

apurv
Light Poster
45 posts since Jan 2007
Reputation Points: 9
Solved Threads: 3
 

i want to know how in c++

hylex
Newbie Poster
1 post since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

// 07/08/10 04:52

/*
  Guess the computers Number game
*/

//main
#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

int main()
{
 double firmver = 0.01;; // Game version
 
 cout << "\t\t\tGuess Num " << firmver;
 cout << "\nCompete with the computer.\nTry to guess the right number!\nSee how thinks faster!\n\n";
 cout << "Do you want to play?(yes/no || y/n)" << endl;
 
 string playgame; // to check if player wants to play
 cin >> playgame;
 cin.get();
 
 // Does player want to play?
 if(playgame == "yes" || playgame == "YES" 
 || playgame == "Yes" || playgame == "y" 
 || playgame == "Y")
 {
  cout << "Press any key to start" << endl;
  
  //Game loop
  while(playgame == "yes" || playgame == "YES" 
 || playgame == "Yes" || playgame == "y" 
 || playgame == "Y")
  {
  int psnum; //player secret num
  int csnum; //computer secret num
 
 
 
 long pgnum; //player guess num   
 int cgnum; // computer guess num
 
 int amountpg = 1; // amount player guesses max 3 times per guess 
 int amountcg = 0; // amount computer guesses max 3 times per guess
 
 psnum = rand() % 50 + 1; // Initiliaze  player secret num from 1-50;
 csnum = rand() % 50 + 1; // Initiliaze  computer secret num from 1-50;
 cout << amountpg << endl;
 
while(amountpg != 3)
 {
 cout << "Please guess your number" << endl;
 
 cin >> pgnum;
 
 if(pgnum == psnum)
 {
  cout << "You guessed right" << endl;
  amountpg = 0;
 }
 
 if (pgnum > psnum)
 {
  cout << "It is too high" << endl;
  amountpg++;
   cout << amountpg << endl;
 }
 
 if (pgnum < psnum)
  {
  cout << "It is too low" << endl;
  amountpg;
   cout << amountpg << endl;
  }
}
  
   cout << "You guessed 3 times wrong! Concentrate on solving the next guess" << endl;
   psnum = rand() % 50 + 1; // Initiliaze  player secret num from 1-50;
   amountpg == 0;
   
}
}
}
registerdt2post
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

how run above program

DIBYENDU SINGHA
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

You need a compiler. There mare many free compilers just a google away.
click here

CJX3711
Newbie Poster
8 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 

Did half a programming class just register to post in this thread?

Duki
Nearly a Posting Virtuoso
1,475 posts since Jun 2006
Reputation Points: 817
Solved Threads: 32
 

#include
#include

using namespace std;

int main()
{
string s;
cout << "Please enter your first name followed by a newline\n";
cin >> s;
cout << "Hello, " << s << '\n';
return 0; // this return statement isn't necessary

devill2
Newbie Poster
1 post since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

If you've got any c++ skillz, you should be able to make this. Learn about random number generation, loops and functions. Then you should be set for a number-style game. :)

ichigo_cool
Junior Poster
101 posts since Jul 2010
Reputation Points: 6
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You