Question

In: Computer Science

The purpose of the program is to play the game of M.A.S.H. (Mansion, Apartment, Shack, House)....

The purpose of the program is to play the game of M.A.S.H. (Mansion, Apartment, Shack, House). This program asks the user multiple questions and then randomly generates answers based on the answers to predict the user’s future. By the time you finish this program, you will have learned how to make a menu based program, use switch statements, validate user input with loops, allow a program to run multiple times until user wants to quit, and mix cin>> and getline() intermittently in a program.

  1. Names of three people (2 they like & one they don’t like)
  1. Three integer numbers between 1 and 100
  2. Three locations including city & state (2 they like & one they don’t like)
  3. Three job titles (2 they like & one they don’t like)
  4. Three companies or restaurants (2 they like & one they don’t like)
  5. Three integer numbers between 10000 and 500000
  6. Three types of cars (2 they like & one they don’t like
  7. You will be predicting the user’s future by selecting one of their three choices randomly. You will need to create a random number for each “category” – this means there should be in total 7 numbers randomly generated between 1 and 3. So for example, you will generate a random number between 1 and 3 for the names of people.

    You will also generate one more random number (this would make 8 total) between 1 and 4 which will indicate if the user will live in a mansion (1), apartment (2), shack (3), or house(4).

  8. Indent and comment your code properly.
  9. MENU - You will have a main menu that will ask the user to either

    1) Play MASH or
    2) End the program.

    You must have a switch statement to figure out which choice the user selected. The program should run over and over until the user selects to end the program using a do-while loop. Use a Boolean variable to help with this!
  10. You MUST validate user input with while loops if the input is a number to ensure the number is in the specified range. You may assume the user will enter in a number (not a character or string), but you can’t assume they enter a number within the specified range.
  11. You MUST allow spaces to be included in all string input.
  12. For housing you are not asking the user for the data. The acronym MASH stands for the different types of housing. There are four choices (Mansion, Apartment, Shack or House). You will need to generate a number between 1 and 4. If it is a 1, you will print out that the user will live in a mansion. If it is a 2, you will print out that the user will live in an apartment……and so on.
  13. For all the other “categories” you have three choices, not four. So you will need to generate a number between 1 and 3. If it is a 1, you print out the first one, 2 the second one, and 3 the third one. For example, for spouse – generate a number between 1 and 3. If it is a 1, then print out the first person that the user said they like. If it is a 2, then print out the second person that the user said they like. If it is a 3, then print out the third person that the user dislikes.    Before printing out the spouse, you should say “You will be happily married to “ and then print out the name.
  14. For the answers you should say something like:
    • You will live in ….
    • You will be happily married to …
    • You and your spouse will have ….. children.
    • You will live in …..      (name city, state here)
    • You will work at ……. (place) as a ……… (job title) making $ ……… (salary) a year.
    • You will drive a ……

Solutions

Expert Solution

code given below:

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include<string>
#include<conio.h>

using namespace std;
void enter()
{
            char name1[100],name2[100],name3[100];
            string city1,city2,city3,job1,job2,job3,comp1,comp2,comp3,car1,car2,car3;
            int c1,c2,c3,c4,c5,c6;
            int r1,r2,r3,r4,r5,r6,r7,mash;
            cin.get();
            cout << "\nEnter Names of three people (2 you like & one you don’t like)\n"; 
            cin.getline (name1, 100);
            cin.getline (name2, 100);
            cin.getline (name3, 100);
            
            
            r1 = 1 + (rand() % 3);
            cout << "\nEnter Three integer numbers between 1 and 100\n"; cin>>c1;cin>>c2;cin>>c3;
            r2 = 1 + (rand() % 3);
            cin.get();
            cout << "\nEnter Three locations including city & state (2 you like & one you don’t like)\n"; getline(cin,city1);getline(cin,city2);getline(cin,city3);
            r3 = 1 + (rand() % 3);
            cout << "\nThree job titles (2 you like & one you don’t like)\n"; getline(cin,job1);getline(cin,job2);getline(cin,job3);
            r4 = 1 + (rand() % 3);
            cout << "\nThree companies or restaurants (2 you like & one you don’t like)\n"; getline(cin,comp1);getline(cin,comp2);getline(cin,comp3);
            
            cout << "\nEnter Three integer numbers between 10000 and 500000\n"; cin>>c4;cin>>c5;cin>>c6; cin.get();
            
            cout << "\nEnter Three types of cars (2 you like & one you don’t like)\n"; getline(cin,car1);getline(cin,car2);getline(cin,car3);
            r5 = 1 + (rand() % 3);
            
            mash = 1 + (rand() % 4);
            
            if (r1==1)
                cout<<"\nYou will be happily married to … "<<name1;
            else if(r1==2)
                cout<<"\nYou will be happily married to … "<<name2;
            else
                cout<<"\n\nYou will be  married to … "<<name3;
                
            if (r2==1)
                cout<<"\nYou and your spouse will have"<<c1<<"children";
            else if (r2==2)
                cout<<"\nYou and your spouse will have "<<c2<<"children";
            else
                cout<<"\n\nYou and your spouse will have"<<c3<<"children";
            
            if (r3==1)
                cout<<"\nYou will live in ….. "<<city1;
            else if(r3==2)
                cout<<"\nYou will live in ….. "<<city2;
            else
                cout<<"\n\nYou will live in ….. "<<city3;
                
            if (r4==1)
                cout<<"\nYou will work at "<<city1<<"as a "<<job1<<" making "<<c4<<"a year.";
            else if(r4==2)
                cout<<"\nYou will work at "<<city2<<"as a "<<job2<<" making "<<c5<<"a year.";
            else
                cout<<"\n\nYou will work at "<<city3<<"as a "<<job3<<" making "<<c6<<"a year.";
            
            if (r5==1)
                cout<<"\nYou will drive a …… "<<car1;
            else if(r5==2)
                cout<<"\nYou will drive a …… "<<car2;
            else
                cout<<"\n\nYou will drive a …… "<<car3;
            
            if (mash==1)
                cout<<"\nYou will live in…… "<<"Mansion";
            else if(mash==2)
                cout<<"\nYou will live in…… "<<"Apartment";
            else if(mash==3)
                cout<<"\nYou will live in…… "<<"Shack";
            else
                cout<<"\n\nYou will live in…… "<<"Home";
            
}

int main()
{  
   
    int n;
    cout<<"press 1. Play Mash\n";
    cout<<"press 2. End proggram\n";
    cin>>n;
    
    switch (n) 
    { 
        case 1: 
            enter();
            break; 
            
        case 2:  
            exit(0);
            break; 
        
        default:  
            cout << "Choice other than 1, 2 "; 
            break;
               
    } 

 return 0; 

}

output:


Related Solutions

Write a program in Basic to play the game of Nim with acom­puter.
Write a program in Basic to play the game of Nim with acom­puter.
Write a LISP program to play either the game "Connect Three" on a size 4x4 game...
Write a LISP program to play either the game "Connect Three" on a size 4x4 game board. Your program must use min-max search and should be invoked by the function call: > (connect-3) The game is single player, human vs the computer AI.
Write a program where a user of this program will play a game in which he/she...
Write a program where a user of this program will play a game in which he/she needs to guess a target number, which is a number that the program has randomly picked in the range that the user chooses. The program will repeatedly prompt for the guessed number and provide a clue whether the guessed number is bigger or smaller than the target number, until the guessed number equals the target number.
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
Frank Ocean decides to play roulette. This game is attractive because the house advantage is small....
Frank Ocean decides to play roulette. This game is attractive because the house advantage is small. If Frank plays and wins big, which of the following is true? a. Frank is a risk taker b. Frank is risk averse c. Frank is a risk neutral d. Frank is a risk-free player
IN C++ Write a program to play the Card Guessing Game. Your program must give the...
IN C++ Write a program to play the Card Guessing Game. Your program must give the user the following choices: - Guess only the face value of the card. -Guess only the suit of the card. -Guess both the face value and suit of the card. Before the start of the game, create a deck of cards. Before each guess, use the function random_shuffle to randomly shuffle the deck.
Write a program with at least 2 functions that play the game of “guess the number”...
Write a program with at least 2 functions that play the game of “guess the number” as follows: Your program chooses the number to be guessed by selecting an integer at random in the range 1 to 1000. The program then displays the following: I have a number between 1 and 1000. Can you guess my number? Please type in your first guess. The player then types the first guess. The program then responds with one of the following: 1.      ...
Write a program to allow a user to play the game Hangman. DO NOT USE AN...
Write a program to allow a user to play the game Hangman. DO NOT USE AN ARRAY The program will generate a random number (between 1 and 4581) to pick a word from the file - this is the word you then have to guess. Note: if the random number you generate is 42, you need the 42nd word - so loop 41 times picking up the word from the file and not doing anything with it, it is the...
Write a LISP program to play the game Tic-Tac-Toe on a size 4x4 game board. Your...
Write a LISP program to play the game Tic-Tac-Toe on a size 4x4 game board. Your program must use min-max search and should be invoked by the function call: > (Tic-Tac-Toe) The game is single player, human vs the computer AI.
write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT