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