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;

}



Related Posts:

  • C Program To Print Chess Board Problem Statement: Write a program in c that will print the chess board. Enter a number to print the board. #include<stdio.h> #include<… Read More
  • C code to implement stack Problem Statement: Write a program in c language to implement stack operation. i) Push ii) Pop iii)Top iv) Display Code: #include<conio.h> … Read More
  • Binary Search In C Problem Statement:  write binary search code in c, that will search for the number in array and find output if the number is found and also … Read More
  • Program To Print Factorial In C Problem Statement: Write a program in c that will print the factorial of a given number using for loop. #include<stdio.h> #include<conio… Read More
  • Semester Project For C Language 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 w… Read More

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