Question: C++ Homework Help! Orriginall Assignment: Write a program that will display a desired message the desired number of times. The program will ask the user

C++ Homework Help!

Orriginall Assignment: Write a program that will display a desired message the desired number of times. The program will ask the user to supply the message to be displayed. It will also ask the user to supply the number of times the message is to be displayed. It will then display that message the required number of times.

New Assignment:

Redo the previous assignment. However, this time, first ask the user to supply the number of times the message is to be displayed and then ask the user to provide the message to be displayed. In other words, reverse the input sequence (first input the count and then the message). Does the program work? By doing the cin first and getline afterwards, the program input wont work correctly. Correct it by adding a cin.ignore( ); after cin statement and before getline statement.

After the program works, turn it in.

Also, in a paragraph, describe, why the program input doesnt work correctly when, after the cin statement, there is a getline statement.

In another paragraph, describe how you corrected the problem.

For each of the code fragments below, answer if the contents of count and message provided are correct or incorrect.

Code Fragment 1:

cout << Enter message count: << endl;

cin >> count;

cout << Enter message: << endl;

getline(cin, message);

User I/O dialog (user input in bold):

Enter message count:

95

Enter message:

I love programming

Contents of count & message variables after the above code fragment executes:

Contents of count:

95

Contents of message:

Code Fragment 2:

cout << Enter message count: << endl;

cin >> count;

cin.ignore( );

cout << Enter message: << endl;

getline(cin, message);

User I/O dialog (user input in bold):

Enter message count:

95

Enter message:

I love programming

Contents of count & message variables after the above code fragment executes:

Contents of count:

95

Contents of message:

I love programming

Code Fragment 3:

cout << Enter message count: << endl;

cin >> count;

cin.ignore( );

cout << Enter message: << endl;

getline(cin, message);

User I/O dialog (user input in bold):

Enter message count:

95

Enter message:

I love programming

Contents of count & message variables after the above code fragment executes:

Contents of count:

95

Contents of message:

Code Fragment 4:

cout << Enter message count: << endl;

cin >> count;

cin.ignore(100, );

cout << Enter message: << endl;

getline(cin, message);

User I/O dialog:

Enter message count:

95

Enter message:

I love programming

Contents of count & message variables after the above code fragment executes:

Contents of count:

95

Contents of message:

I love programming

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!