0

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;
      }

Edited by WaltP: I'm getting tired of adding CODE Tags for people that can't bother reading the Rules!

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

>> 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  += '*';
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.