Answer to Question #235494 in C++ for Dawgie

Question #235494
Write a method that accepts a string and integer n as arguments, the method then displays the passed string n times. Example, if we pass "Testing" as a string and as the integer, function will display ;
Testing
Testing
Testing
Testing
Write a main method demonstrating that the method works correctly by calling it twice, firstly with your first name and last digit on your student number .
1
Expert's answer
2021-09-10T01:47:44-0400
#include<iostream>
#include<string>
using namespace std;




void printString(string stringIn,int n){
	for(int i=0;i<n;i++){
		cout<<stringIn<<"\n";
	}
}


int main()
{
	string stringIn;
	int n;
	cout<<"Enter string: ";
	cin>>stringIn;
	cout<<"Enter n: ";
	cin>>n;
	printString(stringIn,n);
	cin>>n;
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS