164k views
4 votes
Write a function that accepts an argument for a persons name. The method should loop through the number of characters in the name sending each character to the screen each on a separate line.

#include

#include

using namespace std;

int main()

{

Plese fill in.....thanks

User Garethm
by
5.5k points

1 Answer

1 vote

Answer:

#include <iostream>

#include<string.h>

using namespace std;

void printCharacter(string name){

for(int i=0;name[i]!='\0';i++){

cout<<name[i]<<endl;

}

}

int main()

{

string name;

cout<<"enter the name: ";

cin>>name;

printCharacter(name);

}

Step-by-step explanation:

first include the two libraries iostream for input/output and string library for using the string.

then, create the main function and declare the variable type string.

cout instruction is used o display the message on the screen.

cin is used to store the value in the name variable.

after that, call the function. The program control move to the the function. In the function for loop is used to print the character one by one until end of the name.

User Joshholat
by
4.9k points