Created
May 11, 2018 16:52
-
-
Save edenizk/c67a1606c2186feaf44e7dafdbaccc97 to your computer and use it in GitHub Desktop.
guessing game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <windows.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <conio.h> | |
| #include <time.h> | |
| using namespace std; | |
| /* run this program using the console pauser or add your own getch, system("pause") or input loop */ | |
| void progressbar(){ | |
| cout<<"\t\t "; | |
| /*Loading bar*/ | |
| for(int i=0; i<100/5; i++){ | |
| cout<<(char)177; | |
| } | |
| cout<<"<<\r\t\t"; | |
| for(int i = 0; i<=100; i++){ | |
| cout << "\r " << i << "% completed >>" ; | |
| for (int o=1;o<i/5;o++){ | |
| cout<<(char)219; | |
| } | |
| switch (i% 4) | |
| { | |
| case 0: cout<<"\r/"; break; | |
| case 1: cout<<"\r-"; break; | |
| case 2: cout<<"\r\\"; break; | |
| case 3: cout<<"\r-"; break; | |
| } | |
| Sleep(50); | |
| } | |
| cout<<endl; | |
| } | |
| int main(int argc, char** argv) { | |
| int a,b,c,d; | |
| char ch; | |
| do{ | |
| srand(time(NULL)); | |
| cout<<"welcome to guessing game please press a key to continue.\n"; | |
| getch(); | |
| c=1+rand()%(25-1); | |
| cout<<"we are trying to creat a secret number please wait...\n"; | |
| progressbar(); | |
| cout<<"we created a secret number try to find (numbers are between 1-25):)\n"; | |
| do{ | |
| a++; | |
| cin>>b; | |
| //tester | |
| if(cin.fail()||a<=0){ | |
| cin.clear(); | |
| cin.ignore(10, '\n'); | |
| cout<<"Choosen number is negative or not a number\n -Please write it again\n"; | |
| cout<<"please write your guess(it must be a number and it cannot be negative number):\n"; | |
| cin>>b; | |
| if(cin.fail()||a<=0){ | |
| cout<<"Please next time try to write a number or positive number..."; | |
| break; | |
| } | |
| } | |
| //tester | |
| if(b>c){ | |
| cout<<"Your secret number is lower...(please enter a number to guess)\n"; | |
| } | |
| else if(b<c){ | |
| cout<<"Your secret number is higher...(please enter a number to guess)\n"; | |
| } | |
| }while(b!=c);//guess | |
| if(cin.fail()||a<=0){ | |
| cin.clear(); | |
| cin.ignore(10, '\n'); | |
| cout<<"Choosen number is negative or not a number\n -Please write it again\n"; | |
| cout<<"please write your guess(it must be a number and it cannot be negative number):\n"; | |
| cin>>b; | |
| if(cin.fail()||a<=0){ | |
| cout<<"Please next time try to write a number or positive number..."; | |
| break; | |
| } | |
| } | |
| if (a==1){ | |
| cout<<"Congratulations you guessed the first time\n"; | |
| } | |
| else if(a>1) | |
| { | |
| cout<<"Congratulations you guessed correctly in "<<a<<" times \n"; | |
| } | |
| cout<<"do you wanna continue?[Y/N]"; | |
| cin>>ch; | |
| }while(ch=='y'||ch=='Y');//continue | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment