954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pls help me... in array problem..

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...

xxReYMaXxx
Newbie Poster
1 post since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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

]

robertmacedonia
Junior Poster in Training
85 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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 :)

robertmacedonia
Junior Poster in Training
85 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 
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.

CoolGamer48
Posting Pro in Training
401 posts since Jan 2008
Reputation Points: 77
Solved Threads: 40
 

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.

robertmacedonia
Junior Poster in Training
85 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You