Discover a wealth of knowledge at Westonci.ca, where experts provide answers to your most pressing questions. Join our platform to connect with experts ready to provide precise answers to your questions in various areas. Explore comprehensive solutions to your questions from knowledgeable professionals across various fields on our platform.

Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways.
Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is quit.
Ex: If the input is:
apples 5
shoes 2
quito 0
the output is
Eating 5 apples a day keeps the doctor away.
Eating 2 shoes a day keeps the doctor away.
Note: This is a lab from a previous chapter that now requires the use of a loop. LB 334 1 LAB Mad Lib-loops main.cpp Load default template.
1 #include
2 #include
3 using namespace std;
4
5 int main()
6
7 {
8 return;
9
10


Sagot :

Answer:

Following are the code to this question:

#include <iostream>//header file

#include <string>//header file

using namespace std;

int main() //main method

{

   string item;//defining a string variable

   int n;//defining integer variable

   while(cin >>n >>item)//defining while loop to input value  

   {

       if(item == "quito" && n == 0)//use if block to check input value  

       {

           break;//use break keyword

       }

       cout << "Eating " << n << " " << item << " a day keeps the doctor away." << endl;//print input value with the message

   }

   return 0;

}

Output:

Please find the attached file.

Explanation:

In this code, inside the main method one string variable and one integer variable "item, n" is defined, that uses the while loop for input the value and uses the if block that checks string value is equal to "quito" and n value is equal to "0" it breaks the loop, and print the value with the message.

View image codiepienagoya