I am having a little trouble with this coding.

" Write a program that reads into a string object a name with three blanks between the first and last names. Then extract the first and last names and store them in separate string objects. Write a function subprogram that displays its string argument two times. Call this function display the first name for times and then to display the last name six times."
I completed coding the first part of this task with the strings and combining strings together. However, i have having trouble with the other half of this task. It begins from "Write a function subprogram .... to display the last name six times." Can anyone help me with this one. This is where i have so far --

#include <iostream>
#include <string>
using namespace std;


int main()
{
// Defining the strings

string firstname, lastname;
string wholename;
string greet = " Hi ";

// Input and Output
cout << " Please enter your first name: ";
getline ( cin, firstname) ;

cout << " Please enter your last name: ";
getline ( cin, lastname );


wholename = firstname + " " + lastname; // String of first and last join together -- 3 blanks between last and first


cout << greet << wholename << endl; // Display the name with greet + wholename
cout << " You have " << (wholename.length() - 3)
<< " number of letters in your name. " << endl;

cout << " Your initials are: " << firstname.at(0)
<< lastname.at(0) << endl;



system("pause");

return 0;
1
2
3
4
5
6
7
8
9
//outside of main
void function(std::string lastname)
{
  for(int i=0; i<=6;++i)
    std::cout<<lastname<<"\n";
}
//...
//inside of main
  function(lastname);
?

Also, system() is really hated. You can use:
1
2
3
  std::cout<<"Press any key...\n";
  std::string s;
  std::getline(std::cin,s);
Thank you so much poteto :) for your time to help me out
Topic archived. No new replies allowed.