Answer to Question #284807 in C++ for Mittho

Question #284807

The kill monger game c++ code

1
Expert's answer
2022-01-04T13:55:15-0500
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <stdlib.h>



using namespace std;


int main()
{
    int a,b;


    while(b=1)
    {
        cout << "What game you want to play? " << "1. Guess the number  " << "2. Math answers " << "3. Guess the word " << endl;


        cin >> a;


        if (a==1)
        {
            int d;
            int c;
            c = rand() % 100+20;
            cout << "HINT: The number is between " << c-3 << " and " << c+3 <<endl;
            cout << "Enter your guess:"<<endl;
            cin >> d;


            if(d==c)
                cout << "Right answer"<<endl;


            else
                cout << "Wrong answer. The answer is " << c << endl;
        }


        if(a==2)
        {
            int c;
            c=rand() % 20+10;
            int d;
            d = rand() % 14+7;
            int f;


            cout << "What is " << c << " + " << d << " = " <<endl;
            cin >> f;


            if (f==c+d)
                cout << "Right answer!!"<< endl;


            else
                cout<<"Wrong answer! The answer is: " << c+d << endl;
        }


        if (a==3)
        {
            string word;
            string ans;
            int ran;
            ran = rand() % 5+1;


            if(ran==1 || ran==2)
            word = "foobar";


            if(ran==3)
            word = "banana";


             if(ran==4)
            word = "volleyball";


             if(ran==5)
            word = "cricket";


            int l = word.size();


            cout << "Guess the word:  " ;


            for (int i=0;i<l;i++)
            {
                if(i%2==0)
                    cout << word[i];


                else
                    cout << "_";
            }


            cout << endl << "Answer:  ";
            cin >> ans;


            if (word==ans)
                cout << "Right! Play again... " << endl;


            else
                cout << "Wrong! Try again " << endl;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog