Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualFarbodkain

Posted 02 July 2012 - 07:36 AM

Hi everyone,im sorry if i created topic for something like this,but i can't solved the last exercise chapter 2 book Beginning C++ Through Game.i hope someone here can help me
here it is:
they want to switch Player by CPU.i mean player choose number and CPU take guess untile reach the answer.but i don't find way to do that.i start C++ new and i Can't do something like that.i really appreciated if someone help me

here is Original one

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
srand(static_cast<unsigned int>(time(0)));  //seed random number generator

int secretNumber = rand() % 100 + 1;  // random number between 1 and 100
int tries = 0;
int guess;

cout << " Welcome to Guess My Number\n\n";

do
{
  cout << "Enter a guess: ";
  cin >> guess;
  ++tries;

  if (guess > secretNumber)
  {
   cout << "Too high!\n\n";
  }
  else if (guess < secretNumber)
  {
   cout << "Too low!\n\n";
  }
  else
  {
   cout << "\nThat's it! You got it in " << tries << " guesses!\n";
  }

} while (guess != secretNumber);

return 0;
}

#2Farbodkain

Posted 02 July 2012 - 07:32 AM

Hi everyone,im sorry if i created topic for something like this,but i can't solved the last exercise chapter 2 book Beginning C++ Through Game.i hope someone here can help me
here it is:
they want to switch Player by CPU.i mean player choose number and CPU take guess untile reach the answer.but i don't find way to do that.i start C++ new and i Can't do something like that.i really appreciated if someone help me

here is Original one
[source lang="cpp"]// Guess My Number// The classic number guessing game#include <iostream>#include <cstdlib>#include <ctime>using namespace std;int main(){ srand(static_cast<unsigned int>(time(0)));  //seed random number generatorint secretNumber = rand() % 100 + 1;  // random number between 1 and 100int tries = 0;int guess; cout << " Welcome to Guess My Number\n\n";do{  cout << "Enter a guess: ";  cin >> guess;  ++tries;  if (guess > secretNumber)  {   cout << "Too high!\n\n";  }  else if (guess < secretNumber)  {   cout << "Too low!\n\n";  }  else  {   cout << "\nThat's it! You got it in " << tries << " guesses!\n";  }} while (guess != secretNumber); return 0;}[/source]

#1Farbodkain

Posted 02 July 2012 - 07:30 AM

Hi everyone,im sorry if i created topic for something like this,but i can't solved the last exercise chapter 2 book Beginning C++ Through Game.i hope someone here can help me
here it is:
they want to switch Player by CPU.i mean player choose number and CPU take guess untile reach the answer.but i don't find way to do that.i start C++ new and i Can't do something like that.i really appreciated if someone help me

here is Original one
[source lang="cpp"]// Guess My Number// The classic number guessing game#include <iostream>#include <cstdlib>#include <ctime>using namespace std;int main(){    srand(static_cast<unsigned int>(time(0)));  //seed random number generator int secretNumber = rand() % 100 + 1;  // random number between 1 and 100 int tries = 0; int guess;     cout << "\tWelcome to Guess My Number\n\n"; do {  cout << "Enter a guess: ";  cin >> guess;  ++tries;  if (guess > secretNumber)  {   cout << "Too high!\n\n";  }  else if (guess < secretNumber)  {   cout << "Too low!\n\n";  }  else  {   cout << "\nThat's it! You got it in " << tries << " guesses!\n";  } } while (guess != secretNumber);    return 0;}[/source]

PARTNERS