Question

In: Computer Science

Example of how it needs to be done, one at a time instead of asking all...

Example of how it needs to be done, one at a time instead of asking all 3 at once

#include <iostream>
#include <string>
#include <time.h>

using namespace std;

int main(){
int rnum = ((rand()%3-1)+1)+1;
string car1,car2,car3;
cout << "Enter a vehicle you like:";
getline(cin, car1);
cout << "Enter a vehicle you like:";
getline(cin, car2);
cout << "Enter a vehicle you dislike:";
getline(cin,car3);
switch(rnum){
case 1:
cout<< "You will drive "<< car1 << endl;
break;
  
case 2:
cout<< "You will drive "<< car2 << endl;
break;
  
default:
cout<< "You will drive "<< car3 << endl;
}
}

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.
INPUT
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

RANDOM NUMBERS
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).
OUTPUT
1   The user’s type of house (mansion, apartment, shack, or house)
2   The user’s spouse (based on the three people)
3   The number of children the user will have (based on the integer between 1 and 100)
4   Where the user will live (based on locations)
5   Where the user will work, their job title, and their salary (based on the three companies and the three integer numbers between 10000 and 500000).
6   What the user will drive. (based on cars)
SPECIFICATIONS
•   Indent and comment your code properly.

•   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!

•   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.


•   You MUST allow spaces to be included in all string input.

HOW TO PRINT OUT RESULTS
•   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.

•   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.

•   For the answers you should say something like:
o   You will live in ….
o   You will be happily married to …
o   You and your spouse will have ….. children.
o   You will live in ….. (name city, state here)
o   You will work at ……. (place) as a ……… (job title) making $ ……… (salary) a year.
o   You will drive a ……

Solutions

Expert Solution

#include <iostream>
#include <string>
#include <time.h>

using namespace std;
int random(int){
      srand((unsigned) time(0));
    int rnum = (rand()%3+1);
    return rnum;
}
int main(){
    int f=0,choice;
    do{
    cout<<"1)Play MASH or 2) End Program"<<endl;
    cin>>choice;
    switch (choice) { 
    case 1: { 
    string per1,per2,per3;
    cout<<"Enter the name of a person you like:";
    getline(cin,per1);
    cout<<"Enter the name of a person you like:";
    getline(cin,per2);
    cout<<"Enter the name of a person you dislike:";
    getline(cin,per3);
    
    
    int a,b,c;
    cout<<"Enter a number between 1-100:";
    cin>>a;
    if(a<100&&a>1){
        a=a;
    }
    else{
        a=0;
        cout<<"Enter a valid number"<<endl;};
    cout<<"Enter a number between 1-100:";
    cin>>b;
     if(b<100&&b>1){
        b=b;
    }
    else{
        b=0;
        cout<<"Enter a valid number"<<endl;};
    cout<<"Enter a number between 1-100:";
    cin>>c;
     if(c<100&&c>1){
        c=c;
    }
    else{
        c=0;
        cout<<"Enter a valid number"<<endl;};
    
    
    
    string loc1,loc2,loc3;
    cout<<"Enter the name of a city or state you like:";
    cin>>loc1;
    cout<<"Enter the name of a city or state you like:";
    cin>>loc3;
    cout<<"Enter the name of a city or state you dislike:";
    cin>>loc2;
    
    
    string job1,job2,job3;
    cout<<"Enter a Job title you like :";
    getline(cin,job1);
    cout<<"Enter a Job title you like :";
    getline(cin,job2);
    cout<<"Enter a Job title you like :";
    getline(cin,job3);
    
    string com1,com2,com3;
    cout << "Enter a company or restaurant you like:";
    getline(cin, com1);
    cout << "Enter a company or restaurants you like:";
    getline(cin, com2);
    cout << "Enter a company or restaurant you dislike:";
    getline(cin,com3);
    
    
    int n,l,m;
    cout<<"Enter a number between 10000 and 500000";
    cin>>n;
    if(n<100&&n>1){
        n=n;
    }
    else{
        n=0;
        cout<<"Enter a valid number"<<endl;};
    cout<<"Enter a number between 10000 and 500000";
    cin>>l;
    if(l<100&&l>1){
        l=l;
    }
    else{
        l=0;
        cout<<"Enter a valid number"<<endl;};
    cout<<"Enter a number between 10000 and 500000";
    cin>>m;
    if(m<100&&m>1){
        m=m;
    }
    else{
        m=0;
        cout<<"Enter a valid number"<<endl;};
    
    
    string car1,car2,car3;
    cout << "Enter a vehicle you like:";
    getline(cin, car1);
    cout << "Enter a vehicle you like:";
    getline(cin, car2);
    cout << "Enter a vehicle you dislike:";
    getline(cin,car3);
    //1
     switch(random(0)){
    case 1:
    cout<< "You will live in a Mansion"<< endl;
    break;
      
    case 2:
    cout<< "You will live in a Apartment"<< endl;
    break;
    case 3:
    cout<<"You will live in a Shack"<<endl;
    break;
    default:
    cout<< "You will live in a House"<< endl;
    }
    
    //2
    switch(random(1)){
    case 1:
    cout<< "You will be happily married to "<< per1 << endl;
    break;
      
    case 2:
    cout<< "You will be happily married to "<< per2 << endl;
    break;
      
    default:
    cout<< "You will be happily married to "<< per3 << endl;
    }
    //3
    switch(random(2)){
    case 1:
    cout<< "You  and your spouse will have "<< a<<" children."<<endl;
    break;
      
    case 2:
    cout<< "You and your spouse will have  "<< b<<" children."<< endl;
    break;
      
    default:
    cout<< "You and your spouse will have "<< c<<" children."<< endl;
    }
    //4
    switch(random(3)){
    case 1:
    cout<< "You will live in "<< loc1 << endl;
    break;
      
    case 2:
    cout<< "You will live in  "<< loc2 << endl;
    break;
      
    default:
    cout<< "You will live in  "<< loc3 << endl;
    }
    //5
    switch(random(5)){
    case 1:
    cout<< " You will work at  "<< com1 ;
    break;
      
    case 2:
    cout<< "Y You will work at  "<< com2 ;
    break;
      
    default:
    cout<< " You will work at  "<< com3;
    }
    
    //6
    switch(random(4)){
    case 1:
    cout<< "as a  "<< job1;
    break;
      
    case 2:
    cout<< "as a  "<< job2 ;
    break;
      
    default:
    cout<< "as a  "<< job3;
    }
    //7
    switch(random(6)){
    case 1:
    cout<< "making $  "<< n << endl;
    break;
      
    case 2:
    cout<< "making $ "<< l << endl;
    break;
      
    default:
    cout<< "making $  "<< m << endl;
    }
    //8
    switch(random(7)){
    case 1:
    cout<< "You will drive "<< car1 << endl;
    break;
      
    case 2:
    cout<< "You will drive "<< car2 << endl;
    break;
      
    default:
    cout<< "You will drive "<< car3 << endl;
    }
 
        break; 
    } 
    case 2: { 
        f++; 
        cout<<"Thanks for Playing";
        break; 
    } 
    default: 
        cout<<"Wrong Input"<<endl; 
    } 
}
while(f==0);
}

Related Solutions

Done in c++ Read this file one time to determine how many records it contains. Be...
Done in c++ Read this file one time to determine how many records it contains. Be sure to check for a successful file open here. Close the file. Allocate memory dynamically to store the data from step 1. This dynamically allocated memory should be for an array of strings. The array size should be exactly the number of records from step 1. Reopen the file and read it a second time, storing each record into the array of strings from...
Needs to be done in excel showing all the work The Campbell Company is considering adding...
Needs to be done in excel showing all the work The Campbell Company is considering adding a robotic paint sprayer to its production line. The sprayer's base price is $920,000, and it would cost another $20,000 to install it. The machine falls into the MACRS 3-year class, and it would be sold after 3 years for $500,000. The MACRS rates for the first three years are 0.3333, 0.4445, and 0.1481. The machine would require an increase in net working capital...
Give one example of how in business that the time value of money concepts will be...
Give one example of how in business that the time value of money concepts will be important. Give one examples for your personal life. In your examples use dollar estimates to show the impact
Need an example of finance part in business plan template with all the excel part done
Need an example of finance part in business plan template with all the excel part done
Real time PCR: how is it analyzed? what can be done to improve real time PCR?...
Real time PCR: how is it analyzed? what can be done to improve real time PCR? How do you know if the bullfight was good or not? What does it mean if the real time parameters are high, low, or if there were faults in something in the process seeing the results? Abound in your response. Real time pcr: • How to do? • How it is interpreted? • How it is optimized
What 3 manifest needs does McClelland identify? Give an example of how you can satisfy one...
What 3 manifest needs does McClelland identify? Give an example of how you can satisfy one of the three needs.
NEEDS TO BE DONE IN EXCEL WITH CALCULATIONS. An ARM for 100,000 is made at the...
NEEDS TO BE DONE IN EXCEL WITH CALCULATIONS. An ARM for 100,000 is made at the time when the expected start rate is 5 percent. The Loan will be made with a teaser rate of 2 percent for the first year, after which the rate will be reset. The loan is fully amortizing, has a maturity of 25 years, and payments will be made monthly. a. What will be the payments during the first year? b. Assuming that the reset...
When all is said and done, it's likely to be one of the worst environmental disasters,...
When all is said and done, it's likely to be one of the worst environmental disasters, if not the worst, in U.S. history.9 British Petroleum's (BP) Deepwater Horizon offshore rig in the Gulf of Mexico exploded in a ball of flames on April 20, 2010, killing I1 employees. This initial tragedy set in motion frantic efforts to stop the flow of oil. followed by a long and difficult cleanup process. Although the impacts of the explosion and oil spill were...
1. Instead of asking you to find news articles, I have attached 4 news articles on...
1. Instead of asking you to find news articles, I have attached 4 news articles on how COVID-19 affects America and around the world. 2. Discussion Post Requirements: Pick ONE article. Post a summary in your own words in 2 paragraphs. Discuss how the COVID-19 may impact your life or your family and friends. Identify one possible implication that could affect you for the rest of 2020 1. Will the Coronavirus Bring the End of Globalization_ Don’t Count on It...
All work needs to be shown Consider all observations as one sample of X (1st column)...
All work needs to be shown Consider all observations as one sample of X (1st column) and Y (2nd column) values. Answer the following questions: (20 points) 78 4.4 74 3.9 68 4 76 4 80 3.5 84 4.1 50 2.3 93 4.7 55 1.7 76 4.9 58 1.7 74 4.6 75 3.4 80 4.3 56 1.7 80 3.9 69 3.7 57 3.1 90 4 42 1.8 91 4.1 51 1.8 a) Calculate the correlation coefficient r b) Fit the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT