Help in Hangman

Hello I am making a word Guessing game.. I named it "BITAY" because thats what its called in our country. How can i make it go to Option 1(single player) after clicking 1 and How can i make it go to Option 2(two player) after clicking 2. I am not yet done with this project. But i have done planning for what will i put in single player and two player.

Here is my code:

//Hangman
#include <iostream>
#include <string>
#include <conio.h>
#include <stdlib.h>
using namespace std;

void cls()
{
cout << string(1000, '\n');
}

int main()
{
int a=0;
int options=3;
char letter;
string word;


cout<<"\t\t\t\t"<<"++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"\t\t\t\t"<<" +|BBBBBB BB BBBBBBBB BB BB BB |+"<<endl;
cout<<"\t\t\t\t"<<" +|BB BB BB BBBBBBBB BBBB BB BB |+"<<endl;
cout<<"\t\t\t\t"<<" +|BB BB BB BB BB BB BBBB |+"<<endl;
cout<<"\t\t\t\t"<<" +|BBBBBB BB BB BB BB BB |+"<<endl;
cout<<"\t\t\t\t"<<" +|BB BB BB BB BBBBBB BB |+"<<endl;
cout<<"\t\t\t\t"<<" +|BB BB BB BB BB BB BB |+"<<endl;
cout<<"\t\t\t\t"<<" +|BBBBBB BB BB BB BB BB |+"<<endl;
cout<<"\t\t\t\t"<<"++++++++++++++++++++++++++++++++++++++++"<<endl;

cout<< "\t\t\t\t\t" << "--------------------" << endl;
cout<< "\t\t\t\t\t" << "| 1. Single Player |" << endl;
cout<< "\t\t\t\t\t" << "| 2. Two PLayer |" << endl;
cout<< "\t\t\t\t\t" << "| 3. Quit |" << endl;
cout<< "\t\t\t\t\t" << "--------------------" << endl;
cout<< "\t\t\t\t\t" << "Selected : ";
cin>>a;

while (a<1 || a>2)

if (a=3)
{
return 0;
}
cls();





getch();
return 0;

}

Help me please this is my project..

Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>

int main()
{
    bool keep_going = true;
    int option = 0;
    
    do{
        std::cout << "Menu: Please enter 1 or 2\n";
        
        if(std::cin >> option)
        {
            switch (option)
            {
                case 1:
                    std::cout << "Option 1\n";
                    keep_going = true;
                    break;
                case 2:
                    std::cout << "Option 2\n";
                    keep_going = false;
                    break;
                default:
                    std::cout << "1 or 2 and no other integer!\n";
            }
        }
        else
        {
            std::cout << "Wrong input. Must be an integer\n";
            keep_going = true;
            
            std::cin.clear();
            std::cin.ignore(1000, '\n');
        }
        
        }while (keep_going == true);
    
    std::cout << "Escaped to here.\n";
}

Menu: Please enter 1 or 2
qwera
Wrong input. Must be an integer
Menu: Please enter 1 or 2
1
Option 1
Menu: Please enter 1 or 2
3
1 or 2 and no other integer!
Menu: Please enter 1 or 2
2
Option 2
Escaped to here.
Program ended with exit code: 0
Last edited on
Thank you very much!!! ... But what if there are three options, like mine?
Last edited on
closed account (48T7M4Gy)
Then just add more cases.
Hi,
> But what if there are three options, like mine?

Try this :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
int main()
{
    bool keep_going = true;
    int option = 0;
    
    do{
        std::cout << "Menu: Please enter 1 or 2 or 3\n";
        
        if(std::cin >> option)
        {
            switch (option)
            {
                case 1:
                    std::cout << "Option 1\n";
                    keep_going = true;
                    break;
                case 2:
                    std::cout << "Option 2\n";
                    keep_going = false;
                    break;
                case 3:
                    std::cout << "Option 3\n";
                    keep_going = true;
                    break;
                default:
                    std::cout << "1 or 2 or 3 and no other integer!\n";
            }
        }
        else        {
            std::cout << "Wrong input. Must be an integer\n";
            keep_going = true;
            
            std::cin.clear();
            std::cin.ignore(1000, '\n');
        }
        
        }while (keep_going == true);
    
    std::cout << "Escaped to here.\n";
}
oh ok :)
Does that help you? :)
yeah thanks,, but do you know the code about second player mode in hangman when the 2nd player needs to look away and then the 1st player needs to guess what he type.. Just need simple codes :)
Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/194394/
Topic archived. No new replies allowed.