Create a program that prompts the user for their first name, then displays it with asterisks between each letter. Do not include an asterisk in the beginning nor the end.

For example, Sharon would be displayed as: S*h*a*r*o*n .


Here is what I have so far:

#include <cmath>
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
string populate(string array1[], int number);

int main()
{
    string tscore[26]={};
    populate(tscore,26);
    system("pause");
    return 0;
}

string populate(string array1[], int number)
{
    string input;
    int i;
    
    
    cout << "Please enter your name ";
    cin >> input;
    
  
    
    
    {
      cout << "Your name is: " << endl;
      cout << input;
      for(i=0;i<=1;i++)
    cout << "*";
      array1[i]=input;
      
      }
      system("pause");
      return EXIT_SUCCESS;
      }

>> string tscore[26]={};
You don't need to create an array of std::string objects. Just one will do, such as std::string tscore; This code will give you one string with embedded '*' s. Note that you will have to add code that prevents the last '*' from being in the string.

cout << "Your name is: ";
for(int i = 0; i < name.size(); i++)
{
    tscore += name[i];
    tscore  += '*';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.