SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
C++ Basics
Exercise:
Programming Projects
Question:14 | ISBN:9780321531346 | Edition: 7

Question

14. Write a program that plays the game of Mad Lib. Your program should prompt the user to enter the following strings:

■ The first or last name of your instructor

■ Your name

■ A food

■ A number between 100 and 120

■ An adjective

■ A color

■ An animal

After the strings are input, they should be substituted into the story below and output to the console.

Dear Instructor [Instructor Name],

I am sorry that I am unable to turn in my homework at this time.First, I ate a rotten [Food], which made me turn [Color] and

extremely ill. I came down with a fever of [Number 100-120]. Next, my [Adjective] pet [Animal] must have smelled the remains

of the [Food] on my homework, because he ate it. I am currently rewriting my homework and hope you will accept it late.

                                                                                                                                                                                               Sincerely,

                                                                                                                                                                                               [Your Name]

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program:

//Header files 
#include<iostream>
#include <string>
using namespace std;

//main function
void main()
{  
     //Declaration the variables
    string instructor, Name, food, adjective, color, animal;
	double number;

    //Get the required data from user
	cout<<"Enter your instructor name:\n";
	cin>>instructor;
	
	cout<<"Enter your name:\n";
	cin>>Name;
	
    cout<<"Enter a food:\n";
 	cin>>food;
	
    cout<<"Enter a number between 100 and 120:\n";
	cin>>number;
	
	cout<<"Enter an adjective:\n";
	cin>>adjective;
	
    cout<<"Enter a color:\n";
	cin>>color;

	cout<<"Enter a animal:\n";
	cin>>animal;

	//Dispaly story after substituting the input values
	cout<<"Dear Instructor "<< instructor <<",";
	cout<<"\n\n I am sorry that I am unable to turn in my homework at this time.\n First, I ate a rotten "<< food ;
	cout << " ,which made me turn " << color <<" and extremely ill.\n I came down with a fever of "<< number ;
	cout<<".Next, my "<< adjective << " pet " << animal ;
	cout<<"must have smelled the remains of the "
          << food <<" on my homework, because he ate it."; 
	cout<<"I am currently rewriting my homework and  hope you will accept it late.";
	cout<<"\n\n\t\t\t\t\tSincerely,"<<"\n\t\t\t\t\t"<< Name <<endl;
	
	 system("pause");
}

 

Sample run:

0 0

Discussions

Post the discussion to improve the above solution.