helow, can someone help me with my problem. my Teacher give me a problem, he want me to make an array that the output would be my name, buth with a space on it,

example:

Raymond

output:

R a y m o n d
&
R

a

y

m

o

n

d

using array,, pls help me i dont know how to start. im just new with this type of problem...

Recommended Answers

All 6 Replies

Member Avatar for iamthwee

Write down on a piece of paper the steps, from start to finish to get the job done.

For example,

1) Prompt user for name;
2) Store name in char array/ std::string.
3) Get length of name...

etc

I just got some kind of solution, I think it would work. Try this out, and please tell me if it does the job. Cause I'm a new guy too :)


[

#include <iostream>
using namespace std;
void main ()
{
	char name[30];
	cout<<"Enter a name ";
	cin.getline(name,30);
	for (int i = 0; i < strlen(name);i++)
	{
		cout<<name[i]<<endl;
	}
	
}

]

Member Avatar for iamthwee

I just got some kind of solution, I think it would work. Try this out, and please tell me if it does the job. Cause I'm a new guy too :)

#include <iostream>

using namespace std;

void main ()
{
  char name[30];
  cout << "Enter a name ";
  cin.getline ( name, 30 );
  for ( int i = 0; i < strlen ( name ); i++ )
  {
    cout << name[i] << endl;
  }
}

>void main ()
That should be int main()

>for ( int i = 0; i < strlen ( name ); i++ )
It is expensive using strlen() within a for loop like that, I by that I don't mean $$.

It also doesn't help doing somebody else's homework.

Man, I realise that you could solve the problem right away, I know you guys are experienced and these problems are too easy for you. I just wanted to help the dude like some of you guys helped me. And now that he's got the solution, he can look at it, and get new ideas and maybe surprise his teacher, who knows :)

Man, I realise that you could solve the problem right away, I know you guys are experienced and these problems are too easy for you. I just wanted to help the dude like some of you guys helped me. And now that he's got the solution, he can look at it, and get new ideas and maybe surprise his teacher, who knows :)

Or he could submit it as his homework without giving it a second glance. By making him give us some code first or at least ask a specific question, we know that he's tried on his own first, and by only giving pieces of the answer, we know that he's doing some (and hopefully most) of the work.

OK, I won't do this again, I promise. And dude, try to understand the solution. it wasn't easy for me to write it, I'm a newbie you know.

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.