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!!!

Recommended Answers

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

Jump to Post

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.

Jump to Post

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

Jump to Post

All 10 Replies

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.

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 ??

i want to know how in c++

// 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;
   
}
}
}

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

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

#include<iostream>
#include<string>

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

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. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.