Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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 And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

More Books

Students also viewed these Databases questions