Monday, 4 May 2015

Semester Project For C Language

semester project in c
Here is a letter guessing game in c language. You can use this code as your semester project. First enter the word and your name. It will ask you word.length() times to guess letters. you have to guess any letter and it will tell you how many times you guessed right letter.




#include<conio.h>

#include<string.h>

#include <stdio.h>



main()

{

    char word[30],alpha[30],*found;  // word = letter to guess, alpha = alphabates

    int score,i,lenght,num,L,p,j,count,end,k;

    j=0;

    count=0;

    end=0;

    printf("\n ENTER THE WORD:   ");

    // ask input from user

    gets(word);

    score=0;

    num=0;

    p=0;

    // length of word

    lenght=strlen(word);

   

   

    //store player name

    char player_name[70];

    printf("\n ENTER YOUR NAME:  ");

    scanf("%s",player_name);

    char h;

    printf("\n start guessing the letters!!! ");

    h='_';

    printf("\n the word to guess =  ");

    // print "_"

    for(i=0;i!=lenght;i++)

    {

    printf("%c ",h);

    }

    //start guessing letters

    for(i=0;i!=lenght;i++)

    {

        p=1;

        num=num+1;  // letter number

        count=0;

        end=0;

       

        //guess letter

        printf("\n\n  LETTER %d = ",num);

        scanf("%s",&alpha[num]);

       

        //search letter into word

        found=strchr(word,alpha[num]);

        //if letter found

        if(found)

        {

            //Now find position of letter    

            for(j=0,k=1;j!=lenght;j++,k++)

            {

                if(alpha[num]==word[j])

                {

                    count++; // count of letter in word

                }

                else

                {

                    count=count;

                }

            }

            for(j=num;j!=0;j--)

            {

                if(alpha[num]==alpha[j])

                {

                    end++;

                }

                else

                {

                    end=end;

                }

            }

            if(count>=end)

            {// tell position of letter and increment the score

                score=score+1;

                printf("\n OK\n");

                for(L=0;alpha[num]!=word[L];L++)

                {

                    p++;

                }

                printf("\n\n\t\t the letter is at position: %d\n",p);

                printf("\n\t\t ===================\n");

                printf("\n\t\t*********************\n");

            }

            else

            {

                // if letter is asked repetatively

                score=score;

                printf("\n\t\t\t NOT AGAIN!\n");

            }

        }

        else

        {   //if letter  not found

            score=score;

            printf("\n\n\t\t\t NO!!!\n");

        }

    }

    printf("\n THE WORD IS '%s'\n",word);

    printf("\n YOUR SCORE IS %d OUT OF %d",score,lenght);

    getch();

    return 0;

}



1 comment:

  1. TINNINE IN Food | TITANIA's TINNINE-ART
    TINNINE is a spicy, flavorful, versatile and spicy aluminum vs titanium habanero pepper, chi titanium flat iron with a microtouch titanium trim walmart complex harmony of habanero, serrano 2014 ford fusion energi titanium and mango, 2020 ford ecosport titanium making it one of the

    ReplyDelete