1 Replies - 785 Views - Last Post: 08 February 2009 - 08:54 PM Rate Topic: -----

#1 mono15591   User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 406
  • Joined: 05-November 08

My guessing game!

Posted 08 February 2009 - 08:52 PM

#include <iostream>
#include <time.h>
#include <string>
#include <algorithm>
using namespace std;

int main(int argc, char* argv[])
{

	bool option = true; 
	srand(time(NULL));
	int randNum,guess;
	randNum = rand() % 100 + 1;

	do {
	
	cout<< "Pick your number " << endl;
	cin>> guess;


	if (guess == randNum )
		{
			cout<< "You guessed right!";
			cin.sync();
			cin.clear();
			cin.get();
			option = false;
		}
	else 
		{
			if (guess > randNum)
				{
					cout<< "Too high, try again" << endl;
					option = true;
				}
			else 
				{
					cout<< "Too low, try again" << endl;
					option = true;
				}
		}
	} while (option == true);

	return 0;
} 


No problems just wanted to show everyone haha

Is This A Good Question/Topic? 0
  • +

Replies To: My guessing game!

#2 pr4y   User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: My guessing game!

Posted 08 February 2009 - 08:54 PM

This should either be submitted as a C++ Snipplet or moved to "Share your Project".


This forum is for help.


Anyways, if you were looking for some form of "Congratulations" for making a random number guessing game...

Congratulations for completing Homework Assignment #1 in Intro to C++.

:)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1