Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 3 : Change the previous program (newproverb3.cpp ) so the user may input the word to end the phrase. The string holding the users

Exercise 3: Change the previous program (newproverb3.cpp ) so the user may input the word to end the phrase. The string holding the users input word will be passed to the proverb function instead of passing a number to it. Notice that this change requires you to change the proverb function heading and the prototype as well as the call to the function.

// This program will allow the user to input from the keyboard

// whether the last word to the following proverb should be party or country:

// "Now is the time for all good men to come to the aid of their _______"

// Inputting a 1 will use the word party. Any other number will use the word //country.

// PLACE YOUR NAME HERE

#include

#include

using namespace std;

// Fill in the prototype of the function writeProverb.

void writeProverb(int number)

{

if (number == 1) {

cout << "Now is the time for all good men to come to the aid of their party" << endl;

}

else if (number == 2) {

cout << "Now is the time for all good men to come to the aid of their country" << endl;

// Fill in the body of the function to accomplish what is described above

}

else {

while (number != 1 || number != 2) {

cout << "Invalid number. Please enter another number." << endl;

cin >> number;

if (number == 1) {

cout << "Now is the time for all good men to come to the aid of their party" << endl;

break;

}

else if (number == 2) {

cout << "Now is the time for all good men to come to the aid of their country" << endl;

break;

}

}

}

}

int main()

{

int wordCode;

cout << "Given the phrase:" << endl;

cout << "Now is the time for all good men to come to the aid of their "

<< endl;

cout << "Input a 1 if you want the sentence to be finished with party"

<< endl;

cout << "Input any other number for the word country" << endl;

cout << "Please input your choice now" << endl;

cin >> wordCode;

cout << endl;

writeProverb(wordCode);

system("pause");

return 0;

}

// *****************************************************************************

// writeProverb

//

// task: This function prints a proverb. The function takes a number

// from the call. If that number is a 1 it prints "Now is the time

// for all good men to come to the aid of their party."

// Otherwise, it prints "Now is the time for all good men

// to come to the aid of their country."

// data in: code for ending word of proverb (integer)

// data out: no actual parameter altered

//

// *****************************************************************************

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

Identifying Specific ergonomic problems in Press Metal Sdn Bhd

Answered: 1 week ago

Question

Analyse the various techniques of training and learning.

Answered: 1 week ago