#include "stdafx.h" #include #include #include 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; }