Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!