All pastes #2069863 Raw Edit

C++ code

public cpp v1 · immutable
#2069863 ·published 2011-05-27 04:54 UTC
rendered paste body
#include <iostream>#include <cstdlib>using namespace std;// Generates a random numberint nGenerate(){	int number;	number = rand() % 100 + 1;	return number;}// Asks for imput and displays the text related.void ask(int nNumber, int nLoop){	int nGuess = 0;	cout << "You've tried to guess " << nLoop << " numbers." << endl;	cout << "Guess a random number!" << endl;	//TODO: Not working for some reasong, can't figure out why. Perhaps library problem? Gives no sytnax error or anything though.	cout << "In order to exit, please type in 1000 at any time!" << endl; 	cout << "Debug info:" << nNumber << endl; //TODO: Remove debug code.	cout << "Please enter a random number from 1-100: ";	cin >> nGuess;	while (nGuess != nNumber)	{		if (nGuess == '1000') 		{			exit(0);		}		if (nGuess > nNumber)		{			cout << endl << "Nope, It's smaller. ";			nGuess = 0;			cin >> nGuess;		}		if (nGuess < nNumber) //BUG: whenever a number followed by punctuation is entered, it just spams the 'it's bigger message'.		{			cout << endl << "Nope, It's bigger. ";			nGuess = 0;			cin >> nGuess;		}	}	cout << endl << "Success!!!" << endl;}int main(){	// nLoop is more for statistical info, to see how many loops I've been through.	int nLoop = 0;	while (nLoop != 1000) //Used a loop, because I want the person to guess multiple number in row ;)	{	int nNumber = nGenerate(); //TODO: Numbers generated are not really random, need a seed.	ask(nNumber,nLoop);	nLoop++;	}	return 0;}