Question
Topics Loops For Statement would you please provide the answer to this challenge using for loop . Much appreciated!! Description In this assignment, you will
Topics
Loops
For Statement
would you please provide the answer to this challenge using for loop . Much appreciated!!
Description
In this assignment, you will redo a previous assignment using a For loop. The assignment is as follows:
Write a program that will display a message a certain number of times. The program will ask the user to enter the message to be displayed. It will then ask the user to enter the total number of times that the message is to be displayed. It will then display the specified message the required number of times. At the end, it will display Bye.
Testing
Input Test Run 1
Enter the message to be displayed
I love programming.
Enter total number of times message is to be displayed
5
Output Test Run 1
I love Programming.
I love Programming.
I love Programming,
I love Programming,
I love Programming,
Bye.
Sample Code
/*
Java code
*/
import javax.swing.*;
public class Message
{
public static void main(String[] args)
{
String in, out, message;
int count, totalCount;
//input message to be displayed.
in = JOptionPane.showInputDialog
("Enter the message to be displayed");
message = in;
//input the total count the message is to be displayed.
in = JOptionPane.showInputDialog
("Enter total number of times message is to be displayed");
totalCount = Integer.parseInt(in);
//Initialize out String
out = ;
//Write the For statement to display message.
for ( )
{
}
//display message
//write code to display String out
//display bye.
JOptionPane.showMessageDialog(null, "Bye.);
}
}
/*
C++ code
*/
public void main( )
{
String message;
int count, totalCount;
//input message to be displayed.
cout << "Enter the message to be displayed";
getline (cin, message);
//input the total count the message is to be displayed.
cout << "Enter total number of times message is to be displayed";
cin >> totalCount;
//Write the For statement to display message totalCount times.
for ( count=0; count < totalCount; count++ )
{
//display message
}
//display bye.
cout << "Bye. << endl;
}
My code :
#include
using namespace std;
int main() {
string message; int count; int totalCount;
cout<<"Enter the message to be displayed "; getline(cin, message);
cout <<"Enter total number of times message is to be displayed."; cin >> totalCount;
for (count=0; count< totalCount; count++){
cout <<""<
} cout<<"Bye."< return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started