Thursday, August 29, 2013

Hangman *Beta

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.

Wednesday, August 28, 2013

About the site

About the Blog

Hey guys,
this is one of the FOUR blogs run by us to guide students and programmers with different level of programming skills in C,C++ and Python to improve and explore themselves regularly.

In this site we cover few commonly played puzzle games in THREE different programming languages.
Later on we will provide an even more complex but efficient way of doing the same programs so that the transition is smooth.

For anyone who wants to clear up on their basic first we do run Three other blogs to help you out with C, C++ and Python.

For C Programming
For C++ Programming
For Python Programming

Make sure you subscribe to them for regular updates.

Happy Coding!:)

About Us

We both are Computer Science Undergrads at BNM Institute of Technology from Bangalore, India.
This is just a hobby to encourage our fellow students and juniors to explore what basic programming skills can achieve and to help improve on neglected challenging parts of Programming:)

A Simple TicTacToe C++ game code

Everyone has played Tic Tac Toe right? On phone, on paper etc... (During class hours too:))
Well we got a little bored of the game and couldn't find anything else so decided to write a program for it.


We as usual wrote an Algorithm and Coded it in C++ with the intension of modifying it later.

Here's the code:


//
//  main.cpp
//  tictactoe
//
//  Created by Kevin Prasanna and Akash Ashok on 24/08/13.
//  Copyright (c) 2013 Kevin Prasanna. All rights reserved.
//

#include <iostream>
using namespace std;

int i,j;
char mat[3][3];
void display(int i,int j)
{
    for (i=0; i<3; i++) {
        for (j=0; j<3; j++) {
            cout<<mat[i][j]<<"\t\t";
        }
        cout<<"\n\n";
    }
}
void check(int count)
{
    char c;
    if(count%2==0)
        c='X';
    else
        c='O';
    
    if((mat[0][0]==c&&mat[0][1]==c&&mat[0][2]==c)||(mat[1][0]==c&&mat[1][1]==c&&mat[1][2]==c)||(mat[2][0]==c&&mat[2][1]==c&&mat[2][2]==c)||(mat[0][0]==c&&mat[1][0]==c&&mat[2][0]==c)||(mat[0][1]==c&&mat[1][1]==c&&mat[2][1]==c)||(mat[0][2]==c&&mat[1][2]==c&&mat[2][2]==c)||(mat[0][0]==c&&mat[1][1]==c&&mat[2][2]==c)||(mat[0][2]==c&&mat[1][1]==c&&mat[2][0]==c))
    {
        cout<<"Player "<<c<<"\tWins\n\n";
    }
    else return;
    exit(0);
}

int main(int argc, const char * argv[])
{
    int count=0;
    for (i=0; i<3; i++)
        for (j=0; j<3; j++)
            mat[i][j]='_';
    cout<<"Tic Tac Toe 2 players\n"<<"Player 1: X \nPlayer 2: O\n\n\n";
    display(i, j);
    while (count!=9) {
        if(count%2==0)
        {
            cout<<"Player 1 enter co-ordinates\n";
            cin>>i>>j;
            if(mat[i][j]=='_')
            {
                mat[i][j]='X';
            }
            else{
                
               cout<<"Cheater!!!!!!!!!!!!\n";
               count--;
            }
            cout<<"\n\n";
            display(0, 0);
            check(count);
            
        }
        else
        {
            cout<<"Player 2 enter co-ordinates\n";
            cin>>i>>j;
            if(mat[i][j]=='_')
            {
                mat[i][j]='O';
            }
            else
            {
                cout<<"Cheater!!!!!!!!!!!!\n";
                count--;
            }
            cout<<"\n\n";
            display(0, 0);
            check(count);
            
        }
        count++;
    }
    cout<<"\n\n\t\tSHAME!! Its a draw\n";
    return 1;
    
}

The cheating condition:


Winning Condition:


Draw Condition:


This program of of course not an awesome piece of work! But we posted it that way without comments so that you analyse and spend a couple of minutes understanding it. The basic step is very straight forward making this a basic program for beginners. We came up with much more complex data structures that will increase the efficiency but we will bug you with those later.

Any questions? Do comment!

Stay tuned for more AND do look up our other blogs:
For python
For C
For C++

Saturday, August 24, 2013

Welcome!

Hey guys,

Interested in applying to use your basic skills in C,C++ and Python to create some games?

Wondering where to start?

Well the answer is RIGHT HERE!

Stay tuned while we take you on a journey from the basics of coding till we make sure you upload the link sharing your own codes.