Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-30-2008, 06:43 PM
MPax MPax is offline
Newbie
 
Join Date: Mar 2008
Posts: 3
Rep Power: 0
MPax is on a distinguished road
Default A noob question?

I'm to write a small program in which I input 3 words and display the three words from longest to shortest. I was wondering what keyword (which is what I believe they are called) does this. I don't plan on asking you to make said program, just to let me know what keyword needs to be used to do this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-30-2008, 08:05 PM
dcs dcs is offline
Learning Programmer
 
Join Date: Mar 2008
Posts: 60
Rep Power: 2
dcs will become famous soon enough
Default Re: A noob question?

I think you may want to use strlen to determine the length of each string.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-01-2008, 10:57 PM
MPax MPax is offline
Newbie
 
Join Date: Mar 2008
Posts: 3
Rep Power: 0
MPax is on a distinguished road
Default Re: A noob question?

I'm not sure if strlen was working for me so I went and read my textbook and it told me to use string.length() and i've been playing around with it for a little.

I used the header file #include <string> and declared the variables as string (at least I believe I did). I then began using if else to determine how my information would be displayed. At first I was writing:

else if else if (word1.length() > word3.length() > word2.length())
cout << word1 << word3 << word2;

because that is how I understood the book. But I am fairly sure this is incorrect. Can someone please tell me how to do this properly?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-02-2008, 10:51 AM
dcs dcs is offline
Learning Programmer
 
Join Date: Mar 2008
Posts: 60
Rep Power: 2
dcs will become famous soon enough
Default Re: A noob question?

Well, at least now we know you're talking about C++ and not C.
Code:
else if else if (word1.length() > word3.length() > word2.length())
I'm hoping the 'else if else if' is just a typo.

With regard to the condition, you need to separate it a bit.
Code:
if (word1.length() > word3.length() && word3.length() > word2.length() )
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-02-2008, 10:51 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,050
Last Blog:
wxWidgets is NOT code ...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: A noob question?

You're right that your statement is incorrect, since the first > evaluates to 0 or 1, which probably isn't greater than word2.length().
Try:
else if (word1.length() > word3.length() && word3.length() > word2.length())
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-02-2008, 09:14 PM
MPax MPax is offline
Newbie
 
Join Date: Mar 2008
Posts: 3
Rep Power: 0
MPax is on a distinguished road
Default Re: A noob question?

Quote:
Originally Posted by WingedPanther View Post
You're right that your statement is incorrect, since the first > evaluates to 0 or 1, which probably isn't greater than word2.length().
Try:
else if (word1.length() > word3.length() && word3.length() > word2.length())
Thank you that worked perfectly. I appreciate the help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-03-2008, 10:27 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,050
Last Blog:
wxWidgets is NOT code ...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: A noob question?

You're welcome. It's a common issue when transitioning from the world of math where we write i<j<k to the world of programming where we have to decode that into i<j and j<k.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about C# user int input TheMagicalRock C# Programming 3 04-01-2008 08:36 AM
n00b class question MerakSpielman C and C++ 15 02-20-2008 10:37 PM
Noob C question Nousferatou C and C++ 4 09-24-2007 10:02 AM
web dev noob question jub jub jedi General Programming 1 03-26-2007 06:41 AM
Best Linux for a noob... PC101 General Programming 14 09-22-2006 09:21 AM


All times are GMT -5. The time now is 11:54 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
sam ........ 20.00000
gaylo565 ........ 18.00000
|pH| ........ 15.00000
WingedPanther ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads