|
||||||
| 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. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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.
|
| Sponsored Links |
|
|
|
|||
|
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? |
|
|||
|
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()) With regard to the condition, you need to separate it a bit. Code:
if (word1.length() > word3.length() && word3.length() > word2.length() ) |
|
|||||
|
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 |
| Sponsored Links |
|
|
|
|||
|
Thank you that worked perfectly. I appreciate the help.
|
|
|||||
|
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 |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |
| 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 |
Goal: 100,000 Posts
Complete: 67%