943,722 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 652
  • C++ RSS
Jul 26th, 2008
0

Pls help me... in array problem..

Expand Post »
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...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xxReYMaXxx is offline Offline
1 posts
since Jul 2008
Jul 26th, 2008
0

Re: Pls help me... in array problem..

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
Last edited by iamthwee; Jul 26th, 2008 at 10:47 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 26th, 2008
0

Re: Pls help me... in array problem..

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


[
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3. void main ()
  4. {
  5. char name[30];
  6. cout<<"Enter a name ";
  7. cin.getline(name,30);
  8. for (int i = 0; i < strlen(name);i++)
  9. {
  10. cout<<name[i]<<endl;
  11. }
  12.  
  13. }
]
Last edited by Tekmaven; Jul 26th, 2008 at 2:15 pm. Reason: Code tags
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
robertmacedonia is offline Offline
85 posts
since Jul 2008
Jul 26th, 2008
0

Re: Pls help me... in array problem..

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

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void main ()
  6. {
  7. char name[30];
  8. cout << "Enter a name ";
  9. cin.getline ( name, 30 );
  10. for ( int i = 0; i < strlen ( name ); i++ )
  11. {
  12. cout << name[i] << endl;
  13. }
  14. }
>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.
Last edited by iamthwee; Jul 26th, 2008 at 11:19 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 26th, 2008
0

Re: Pls help me... in array problem..

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
robertmacedonia is offline Offline
85 posts
since Jul 2008
Jul 26th, 2008
0

Re: Pls help me... in array problem..

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.
Reputation Points: 77
Solved Threads: 40
Posting Pro in Training
CoolGamer48 is offline Offline
401 posts
since Jan 2008
Jul 26th, 2008
0

Re: Pls help me... in array problem..

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

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: vector question
Next Thread in C++ Forum Timeline: problem with counter





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC