Guess Number: Game in C++
Code:
// www.cppfuzz.com (Ahmad Mukhtar) /* ______ .______ .______ _______ __ __ ________ ________ / || _ \ | _ \ | ____|| | | | | / | / | ,----'| |_) | | |_) | | |__ | | | | `---/ / `---/ / | | | ___/ | ___/ | __| | | | | / / / / | `----.| | | | | | | `--' | / /----. / /----. \______|| _| | _| |__| \______/ /________| /________| */ #include <iostream> #include <ctime> #include <cstdlib> #include <windows.h> using namespace std; void main() { system("color 0A"); int input,secret; char answer; while (answer!='n'&&answer!='N') { srand(time(NULL)); secret = rand() % 1000 + 1; cout << "I have a number between 1 and 1000." << endl; cout << "Can you guess my number???" << endl; do { cout << "Please type your guess..." << endl; cin >> input; Sleep(500); system("Cls"); if (input<secret) { cout << "Too low, try again." << endl; } if (input>secret) { cout << "Too high,try again." << endl; } } while (input!=secret); cout << endl; cout << "Excellent! You Guessed the number!" << endl; cout << "Would you like to play again (y or n)? "; cin >> answer; } }