All pastes #261900 Raw Edit

Miscellany

public cpp v1 · immutable
#261900 ·published 2006-11-29 23:13 UTC
rendered paste body
#include "stdafx.h"#include <iostream> #include <ctime> #include <cstdlib>using namespace std;int main() {	int random, lowest=1, highest=10, range, index, tries;    srand((unsigned)time(0));    range = (highest-lowest)+1;    for(index=0; index<20; index++){ 		// Generate a random integer        random = lowest + int(range*rand()/(RAND_MAX + 1.0));    }	cout << endl << "Guess a number between 1 and 10: ";	for (tries = 0; tries<10; tries++){		int guess;		cin >> guess;		cout << endl;		if (guess == random) {			cout << "You got it!" << endl;			break;		} else {			if (guess < random) {				cout << "Too low." << endl;			} else { 				cout << "Too high." << endl;			}			cout << "Try again: ";		}	}	cout << "It was " << random << endl;	return 0;}