Monday 21 August 2017

Guess the name project

#include<stdio.h>
#include<stdlib.h>
#define size 20
void loading(void);
void extra(void);
int i,ii,j,k,l;//COUNTER VARIABLES
int RN1,RN2,len,index;//RANDOM NUMBERS,LENGTH of NAME & INDEX of LETTER ENTERED
char ch,chr,name[size],correct[size]="-------------------",wrong[2*size]="---------------------------------------";
char crct[size],wrng[2*size],a,b;
char Boy_Name[180][size]= {
            "Abbas","Ali","Abid","Abrar","Adeel","Adil","Afzal","Afzaal","Ahmed","Kamran",
            "Abdullah","Ahmer","Ahsan","Ajmal","Akbar","Akhtar","Akram","Aqeel","Aqib","Aleem",
            "Shahid","Altaf","Amin","Amir","Amjad","Anwar","Arif","Arsalan","Arshad","Asad",
            "Fawad","Asim","Aslam","Ayaaz","Ayub","Azam","Azeem","Azhar","Aziz","Babar",
            "Hashaam","Bashir","Danial","Danish","Dawood","Ehtisham","Fahad","Faisal","Faiz","Farid",
            "Farrukh","Fawad","Fayaz","Fazal","Hasan","Hussain","Habib","Hafeez","Haider","Hamid",
            "Hameed","Haroon","Harris","Humayun","Ibrahim","Idrees","Iftikhar","Ijaz","Ilyas","Imran",
            "Inzamam","Iqbal","Irfan","Ishaq","Ismail","Jabbar","Jafar","Jalal","Jaleel","Jamal",
            "Jameel","Junaid","Javaid","Jawad","Kabir","Kaleem","Karim","Khalid","Latif","",
            "Mohammad","Mahmood","Majid","Mohsin","Mubashar","Mudassar","Munawar","Murtaza","Musharraf","Mustafa",
            "Muzaffar","Nabeel","Nadeem","Naeem","Nasir","Naseer","Noman","Naveed","Nawaz","Khaliq",
            "Qadir","Qaiser","Qasim","Raza","Rahim","Rahman","Rameez","Rashid","Rauf","Razzaq",
            "Riaz","Rizwan","Saad","Sabir","Sadaqat","Saeed","Saif","Sajid","Saqib","Salim",
            "Khawar","Araib","Salman","Shabbir","Sarfraz","Shafiq","Shahid","Shahzad","Shan","Sheharyar",
            "Sheraz","Shoaib","Shuja","Sohaib","Sohail","Adnan","Tahir","Taimoor","Tanvir","Tariq",
            "Umair","Umar","Usman","Uzair","Waheed","Wajid","Waqar","Wasi","Wasim","Yahya",
            "Yasir","Younis","Yousaf","Zafar","Zaheer","Zahid","Zain","Zaman","Zameer","Zeeshan",
            "Zia","Zohaib","Zubair","Badar","Farooq","Rehman","Waqas","Tabassum","Tasawar","Tayyab"
            };
char Girl_Name[180][size]={
            "Abida","Adeela","Afreen","Afsheen","Aisha","Alina","Amina","Ammara","Ambreen","Arfa",
            "Arzoo","Asma","Atiqa","Azra","Batool","Beenish","Benazir","Bina","Bushra","Fakhra",
            "Farah","Fareeha","Farida","Farzana","Fatima","Firdous","Ghazala","Hajira","Iffat","Irum",
            "Javeria","Kausar","Khadija","Kulsoom","Laila","Lubna","Madeeha","Maimoona","Maleeha","Mariam",
            "Mehek","Momina","Nadira","Nadia","Nafeesa","Nargis","Pakeeza","Parveen","Neelofar","Andaleeb",
            "Hania","Hadia","Hafsa","Hira","Hareem","Tehreem","Rabia","Raeesa","Raheela","Rashida",
            "Ruqaya","Saba","Sabiha","Sadia","Sabahat","Sabeen","Sehar","Saima","Sajida","Sakina",
            "Salma","Sameera","Sana","Sanober","Sara","Seema","Shabana","Shabnam","Shagufta","Shaista",
            "Shakeela","Shamim","Sharmeen","Zoha","Shazia","Shumaila","Sobia","Somaiya","Surayya","Shanza",
            "Sheeza","Tabassum","Tahira","Nasira","Taskeen","Tasneem","Tasawar","Ulfat","Umaira","Uzma",
            "Zunaira","Zahida","Shahida","Yasmeen","Zainub","Zarqa","Zuhra","Zulekha","Aneeqa","Shama",
            "Aalia","Hifza","Aiman","Fazeela","Habiba","Kiran","Aafia","Maleeha","Balqees","Abiha",
            "Arifa","Ambar","Atiya","Warda","Naseem","Sidra","Fozia","Muntaha","Zobia","Saudia",
            "Sofia","Huma","Hina","Sumaira","Rehana","Fajar","Noor","Aiza","Tooba","Resham",
            "Mehwish","Juggan","Iman","Hadiqa","Umaima","Sarwat","Fiza","Mehreen","Tania","Anam",
            "Neelum","Maheen","Iraj","Maham","Gia","Saira","Faiza","Haya","Maria","Meera",
            "Sunbal","Minahil","Natasha","Nosheen","Rubab","Sonia","Zeba","Zara","Deeba","Farwa",
            "Faryal","Fareeha","Mahira","Mahnoor","Maya","Naheed","Nimra","Nirma","Rahat","Sanam"
            };
void main()
    {
    clrscr();
    gotoxy(32,1);
    printf("INSTRUCTIONS:\n\nIn this game, computer will choose a name from a list of names of PAKISTANI boys& girls.\nIt will tell you whether the name chosen is of a BOY or a GIRL and it will");
    printf(" also tell you that how many LETTERS are there in the NAME. It will draw two lines as:----\t(TOTAL NUMBER of LETTERS in NAME)\n--------\t(NUMBER of WRONG characters you can enter)\nwhich");
    printf(" shows that the name chosen consists of 4 LETTERS & you have 8 chances to\nguess the CORRECT LETTERS (i.e. TWICE the LENGTH of NAME).\nThen you will have to START guessing LETTERS");
    printf(" by entering LETTERS. FOR EXAMPLE:\tIf the choosen name is \"ABRAR\" and you guessed \"a\", the computer will put it as:a--a-\n----------\nwhich shows that the letter guessed is PRESENT in");
    printf(" the name at FIRST & FOURTH\nPLACE. NEXT, if you guess \"s\", computer will put it as:\na--a-\ns---------\nwhich shows that the letter guessed is NOT PRESENT in the name. AND SO ON.\nIf the UPPER line fills");
    printf(" before the LOWER line,it means that you have\nSUCCESSFULLY guessed the name. \nIf the LOWER line fills BEFORE the UPPER line, it means that you have FAILED to guess the name. \n\nIf you");
    printf(" want to PLAY, press \"Y\". OTHERWISE, press \"N\" to QUIT. ");
    ch=getch();
//if user wants to play the game.
returnc:i=0;
    if(ch=='Y' || ch== 'y')
        {
        loading();
        strcpy(crct,correct);//copies CORRECT string to CRCT string.
        strcpy(wrng,wrong);//copies WRONG string to WRNG string.
        randomize();
        RN1=random(2);//1st random number.
        RN2=random(180);//2nd random number.
//check if the name to be choosen is of a BOY or a GIRL & assign the choosen name to string NAME.
        if(RN1==0)
            {
            printf("You Have to Guess the Name of a BOY");
            for(ii=0;ii<size;ii++)
                {
                name[ii]=Boy_Name[RN2][ii];
                if(Boy_Name[RN2][ii]=='\0')
                    break;
                }
            }
        else if(RN1==1)
            {
            printf("You Have to Guess the Name of a GIRL");
            for(ii=0;ii<size;ii++)
                {
                name[ii]=Girl_Name[RN2][ii];
                if(Girl_Name[RN2][ii]=='\0')
                    break;
                }
            }
//check LENGTH of NAME choosen.
        len=strlen(name);
        printf("\n\nNAME consists of %d CHARACTERS\n\n",len);
        printf("You have %d chances to guess the correct name\n\n",2*len);
//print the strings CRCT and WRNG.
        for(ii=0;ii<len;ii++)
            printf("%c",crct[ii]);
        printf("\n");
        for(ii=0;ii<2*len;ii++)
            printf("%c",wrng[ii]);


       input1:    for(i=i;;)
            {
        input:  if(i<=2*len)
                {
                index=-1;
                a=b='y';
                printf("\n\n%d chances left",2*len-i);
                printf("\n\nEnter Character ");
                }
                chr=getche();
                printf("\n");
//checks whether the entered character exists in the name or not.
                for(j=0;j<len;j++)
                    if(chr==name[j] || chr==name[j]-32 || chr-32==name[j])
                        {
                        index=j;
                        crct[index]=chr;
                        }
                if(index!=-1)
                    {
                    for(j=0;j<len;j++)
                        if(crct[j]=='-')
                            a='n';
                    if(a=='n')
                        {
                        extra();
                        goto input1;
                        }
                    else
                        {
                        extra();
                        gotoxy(28,13);
                            printf("CONGRATULATIONS! YOU WON");
                        gotoxy(17,15);
                            printf("Press 'y' to PLAY AGAIN or press 'n' to QUIT ");
                                ch=getch();
                        goto returnc;
                        }
                    }
                if(index==-1)
                    {
                    if(i==2*len)
                        goto exit;
                    else
                        for(l=0;l<=2*len;l++)
                            if(wrng[l]=='-')
                                {
                                wrng[l]=chr;
                                goto print;
                                }
                    }
//prints the new strings.
              print:clrscr();
                for(k=0;k<len;k++)
                    printf("%c",crct[k]);
                printf("\n\n");
                for(k=0;k<2*len;k++)
                    printf("%c",wrng[k]);
//Check whether the LOWER line is filled or not. If not, put 'b=n' & take input again until last chance.
                    for(j=0;j<=2*len;j++)
                        if(wrng[j]=='-')
                            b='n';
                    if(b=='n')
                        {
                        i++;
                        goto input;
                        }
                    else if(b=='y')
                        {
                        i++;
                        goto input;
                        }
            exit:   clrscr();
                gotoxy(34,11);
                    printf("SORRY! YOU LOST");
                gotoxy(20,13);
                    printf("The Name that was choosen is \"%s\"",name);
                gotoxy(17,15);
                    printf("Press 'y' to PLAY AGAIN or press 'n' to QUIT ");
                        ch=getch();
                goto returnc;
            }
        }
//if user don't want to play the game.
    else if(ch=='N' || ch=='n')
        {
        clrscr();
        gotoxy(31,12);
            printf("GOOD BYE...TAKE CARE");
        }
//if user enters the wrong input i.e. else than 'y' or 'n'.
    else
        {
        clrscr();
        gotoxy(24,12);
            printf("Press \"Y\" to PLAY & \"N\" to QUIT ");
                ch=getch();
        goto returnc;
        }
    getch();
    }



void extra()
    {
    clrscr();
    for(k=0;k<len;k++)
        printf("%c",crct[k]);
    printf("\n\n");
    for(k=0;k<2*len;k++)
        printf("%c",wrng[k]);
    }




void loading(void)
    {
    int z;
    for(z=5;z>=1;z--)
        {
        clrscr();
        gotoxy(36,10);
            printf("LOADING . . .");
        gotoxy(31,12);
            printf("%d Seconds Remaining",z);
        delay(1000);
        }
    clrscr();
    }

0 comments: