Hey guys this is the beta code for Hangman. It has a default input string (movie name) and checks your number of Correct Guesses as well as Guesses Remaining before you are hanged :-)
Paste the file and run it:)
We will upload the full version with n number of movies soon!
//
// main.cpp
// Hang
//
// Created by Kevin Prasanna on 29/08/13.
// Copyright (c) 2013 Kevin Prasanna. All rights reserved.
//
#include <iostream>
#include <string.h>
using namespace std;
char str[5]={'S','H','R','E','K'},str1[10];
int gs=0;
void init()
{
for (int i=0; i<5; i++) {
str1[i]='_';
}
}
void display(char *str1)
{
cout<<"\n\t\t";
for (int i=0; i<5; i++) {
cout<<str1[i]<<"\t";
}
cout<<"\n\n";
}
char print()
{
char ch;
cout<<"\n\tEnter a character in CAPS\n";
cin>>ch;
return ch;
}
int check(char ch,int gs_rm)
{
for (int i=0; i<5; i++)
{
if (ch==str[i]) {
str1[i]=ch;
gs++;
return gs_rm;
}
}
return gs_rm-1;
}
int main(int argc, const char * argv[])
{
cout<<"\t\t\tWelcome!\n";
int gs_rm=7;
char ch;
init();
display(str1);
while (gs_rm!=0)
{
ch=print();
gs_rm=check(ch,gs_rm);
display(str1);
cout<<"Correct Guesses:"<<gs<<endl;
cout<<"Guesses Remaining:"<<gs_rm<<endl;
if(gs==5)
{
cout<<"\n\t\t\tYou Win\n";
exit(0);
}
}
cout<<"\n \tChances are over\n\tYOU ARE HERE-BY HANGED\n";
return 1;
}
Let's see how it works:
The success condition:)
The Hanging Condition:)
Stay Tuned for more!
Do g+ and subscribe if you like it.
No comments:
Post a Comment