/** Copyright (c) 2012, School of Computer Science, Yantai University * All rights reserved. * file name: test. cpp * Author: Fan Lulu * Completion Date: July 15, December 27, 2012 * version: v1.0 ** input Description: none * Problem description: a random number is generated, requiring the user to guess this number * program output: * Problem Analysis: * Algorithm Design: omitted */# include <iostream> # include <ctime> using namespace std; int main (void) {int num, ran_num, a, B, I = 1; cout <"Enter the range a, B (a <B):"; cin> a> B; srand (time (0); if (B> a) ran_num = (rand () % (B-a) +; cout <"Enter the number you want to guess:" <endl; cin> num; do {if (ran _ Num> num) {cout <"sorry, you guessed it. Please continue:"; cin> num;} else {cout <"sorry, you guessed it was too big. Please continue: "; cin> num;} I ++;} while (num! = Ran_num); if (num = ran_num) {cout <"Congratulations, you guessed it! "<Endl; cout <" You guessed "<I <" times. "<Endl;} return 0 ;}
Experience: It's so fun !!!!!!!!!!