/**************************/ /*Allan Clark Alhilo.cpp*/ /*Nov 13/02 */ /*This program will track */ /*the number of guesses */ /*that a computer makes to*/ /*guess your secret number*/ /**************************/ #include //The library call for input/output #include //The library call for input/output manipulation #include //The library call for clrscr() #include //The library call used to manipulate string variables. #include //The library call to use math equations (sqrt) #include //The library call for random number #include //The library call to acquire the system's date void input(char fname[15], char lname[15], int& guess, int& compguess, int& count) { guess = 0; cout << setiosflags(ios:: fixed); cout << setprecision(0); //Fowler Statement// cout << endl << endl; cout << "\t Cyber Guessing( Hi-Low) Version 0.4" << endl << endl; cout << "\t ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*" << endl; cout << "\t ~ This program will guess the number *" << endl; cout << "\t ~ that the user input with a hilo thing*" << endl; cout << "\t ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*" << endl; cout << endl; cout << " // Allan Clark - Programmer //" << endl << endl; cout << " Press Any Key to Continue"; getch(); // gets character // clrscr(); //Clears the fowler screen and goes to the input screen// cout << "\t\t[]-----------------------------[]" << endl; cout << "\t\t|| ||" << endl; cout << "\t\t|| Welcome to the Cyber ||" << endl; cout << "\t\t|| Guesser Please enter ||" << endl; cout << "\t\t|| your secret number! ||" << endl; cout << "\t\t|| Between 1 and 40 ||" << endl; cout << "\t\t|| ||" << endl; cout << "\t\t[]-----------------------------[]" << endl; cout << endl << " What is your first name?................: "; cin >> fname; cout << endl << endl; cout << " What is your last name?.................: "; cin >> lname; cout << endl << endl; randomize(); compguess = compguess + 1; compguess = random(41); count = 0; do { count++; guess = guess + 1; cout << " What is your GUESSED number?..........: "; cin >> guess; cout << endl; if(guess > 40) { cout << "Your number is too high"; cout << endl; getch(); } if(guess < 1) { cout << "Your number is too low"; cout << endl; } if(guess < compguess) { cout << "Your number is too low"; cout << endl; } if(guess > compguess) { cout << "Your number is too high"; cout << endl; } } while(guess != compguess); } void output(char fname[15], char lname[15], int& guess, int& compguess, int& count) { input(fname, lname, guess, compguess, count); getch(); clrscr(); time_t t=time(NULL); cout<<" " << ctime(&t)<< endl << endl; //Displays the time// cout << "\t\t\t Cyber Guesser" << endl; cout << "\t\t\t ~~~~~~~~~~~~~" << endl; cout << endl << endl; cout << "\tName of User: " << fname << ", " << lname; cout << "\t Secret number: " << compguess << endl; cout << endl << endl; cout << "\tTotal Number of guesses made......: " << count << endl; cout << endl; cout << "\tFinal guess made by you......: #" << guess << endl; cout << endl; } int main(void) { char yes; do { char fname[15], lname[15]; // Declaration of Local Variables // int guess, compguess, count; clrscr(); output(fname, lname, guess, compguess, count); cout << "\t-Thank You For Playing Hi & Low-"; cout << " Do you wish to play again? (y/n) "; cin >> yes; if(yes != 'y') {_exit(0);} } while(yes = 'y'); }