Hi! This is one of my first programs, and My first thread. I was wondering if anyone could tell why, after you miss the missing number twice, the rogram closes, and if there are any ways to optimize this code?Code:#include <cstdlib> #include <iostream> #include <stdlib.h> #include "stdio.h" #include "windows.h" using namespace std; int title() { cout << "W"; Sleep(200); cout<< "e"; Sleep(200); cout<<"l"; Sleep(200); cout<< "c"; Sleep(200); cout <<"o"; Sleep(200); cout <<"m"; Sleep(200); cout <<"e"; Sleep(200); cout <<" "; Sleep(200); cout <<"t"; Sleep(200); cout <<"o"; Sleep(200); cout <<" "; cout <<"."; Sleep(200); cout << "."; Sleep(200); cout << "."; Sleep(2000); cout <<"T\n"; Sleep(200); cout <<" h\n"; Sleep(200); cout <<" e\n"; Sleep(200); cout <<" \n"; Sleep(200); cout <<" G\n"; Sleep(200); cout <<" u\n"; Sleep(200); cout <<" e\n"; Sleep(200); cout <<" s\n"; Sleep(200); cout <<" s\n"; Sleep(200); cout <<" i\n"; Sleep(200); cout <<" n\n"; Sleep(200); cout <<" g\n"; Sleep(200); cout <<" \n"; Sleep(200); cout <<" G\n"; Sleep(200); cout <<" a\n"; Sleep(200); cout <<" m\n"; Sleep(200); cout <<" e\n"; Sleep(200); cout <<" !\n\n\n\n"; Sleep (2000); system("cls"); cout<< "This is a fairly hard game, so if you can win,\n"; cout << "you're either really lucky or extrememly smart.\n\n\n\n"; system("pause"); system("cls"); } int easy() { int wingame=0; int answer; srand((unsigned)time(0)); int random = rand(); int trys =15; cout << "Here we go...\n\n\n\n\n"; do { cout << "What is your guess? -"; cin >> answer; if (answer < random) { cout << "Too Small!\n\n\n"; trys = trys - 1; cout << "Only " << trys <<" trys left!\n\n"; } if (answer > random) { cout << "Too Big!\n\n\n"; trys = trys - 1; cout << "Only " << trys <<" trys left!\n\n"; } if (answer == random) { cout << "Great!\n\n\n"; wingame = 1; Sleep(200); title(); } } while (wingame == 0, trys > 0); if (trys == 0) {cout <<"Sorry! You're out of trys!"; } Sleep(3000); system("cls"); if (wingame == 1) { title(); } } int menu() { int level; cout << "^^-----**Menu**-----^^\n\n\n\n"; cout << "1. Begin the Game\n"; cout << "2. Read Instructions\n\n\n"; // input level of user cout <<"What is your choice? -"; cin >> level; if (level == 1) { easy(); } if (level == 2) { cout << "This is a guessing game!(duh)\n"; Sleep (1000); cout << "You have 10 trys to guess a random number,\n"; Sleep (1000); cout << "which can be either huge or small.\n"; Sleep (1000); cout << "When you finish, e-mail me to tell me how much you hated it!\n\n\n\n\n\n\n\n\n"; system ("PAUSE"); system("cls"); } easy(); } int main() { title(); menu(); system("PAUSE"); return EXIT_SUCCESS; }



LinkBack URL
About LinkBacks


