C++ Program to create Hangman














































C++ Program to create Hangman



Description
Hangman is a paper and pencil game for two or more players. One player thinks of a word, phrase or sentence and the other(s) tries to guess it by suggesting letters or numbers within a certain number of guesses.
Program Code:
//This code is for Turbo C++
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
void main()
{
clrscr();
int i,t=5,j,d=0,f=0,p;
char ch,ch2,str1[20],str2[20],str3[20],letter,let[20];
cout<<" "<<" "<<" "<<"WELCOME TO HANGMAN!!!\n\n";
cout<<"Enter word(Player 1)";
gets(str1);
strupr(str1);
clrscr();
cout<<" ";

cout<<"Player 2 have 5 chances to guess the word"<<endl;
do
{
cout<<"1.Do you want to guess word\n ";
cout<<"Enter choice\n";
cin>>ch;
if(ch=='1')
{
cout<<"Enter word\n";
gets(str2);
strupr(str2);
if(strcmp(str1,str2)==0)
{
cout<<"The answer is correct.You won\n";
break;
}
else
{
t--;
cout<<"The answer is not correct.Try again.\n";
cout<<"Chances left\n"<<t<<endl;
}
if(t==0)
{
cout<<"You have lost\n";
}

}
while(t>0) ;
cout<<"Thanks for playing!!!";
getch();
//This code is for Turbo C++
}

Output





More Articles of Avikrit Kohli:

Name Views Likes
C++ Program To Implement Simpsons 3/8th rule 360 2
C++ Program To Reverse String Without Using String Functions 381 20
C++ Program To Reverse Line In Text File 1243 1
C++ Program To Reverse Each Word In Text File 324 1
C++ Program To Read Text File Word By Word 1428 1
C++ Program To Create And Display Text File 303 1
C++ Program To Find Root Using Newton-Raphson Method 5394 11
C++ Program To Find Root Using Bisection Method 1125 1
C++ Program For Cohen Sutherland Clipping Algorithm 1839 1
To Sort Array Of Integers Using Bubble,Insertion And Selection Sort 317 1
C++ Program To Delete Element In Array At Particular Position 517 1
C++ Program To Insert Element In Array At Given Position 698 1
C++ Program To Implement Stack Using Arrays 331 1
Python Program To Add Source Code of A Webpage 239 1
Python Program To Extract Data From Excel 267 1
C++ Program To Find Sum Of Fibonacci Series Using Recursion 459 1
Program To Display Level Order Transversal Using Queue 254 1
C++ Program To Find The Minimum In Subarray Of Size k Using Deque 267 1
C++ Program To Sort Stack Recursively 857 1
C++ Program To Reverse Stack Recursively 262 1
C++ Program To Insert At Bottom Of Stack Using Recursion 266 1
C++ Program To Create Tower Of Hanoi 2427 1
C++ Program To Convert Infix To Postfix Expression Using Stack 10944 3
C++ Program To Balance Parenthesis Using Stack 963 1
C++ Program To Implement Queue Using Array 2256 2
C++ Program To Sort Two Arrays And Inserting Result In Third array 258 1
C++ Program To Find Length Of Linked List 675 1
C++ Program To Search An Element Recursively In Linked List 293 1
C++ Program To Reverse Linked List Recursively 1153 1
To Find Negation of Number Using Operator Overloading 241 1
C++ Program to create Hangman 2639 1
C++ Program to Swap two numbers without using third variable 318 2

Comments