Write a C++ program that reads from keyboard 3 words, with proper input prompt. Then for these 3 words that were read, the program displays first the word of the longest length, then the word of the shortest length, and finally the remaining last word. You may assume that these 3 words are all different in lengths, or consider a word to be of the longest length if no other words exceed it in length.
lolodede
-2
Newbie Poster
Recommended Answers
Jump to PostI've seen this identical problem just a day or so ago.
Nice you posted your homework problem, now what is it that you expect from us? I don't have my crystle ball at the moment so I can't read your mind.
Jump to Postpost what you have done so far to solve this problem.
Jump to Postline 9. When comparing two strings you have to use the == boolean operator for equality, not the = assignment operator. And the literal string must be in double, not single quotes
if( word == "word1")
line 10: The comparison on line 9 does not check for word length so …
Jump to Post
char word, word1, word2,word3, length;
You've declared everything as chars, not strings. A char is ONLY ONE character, not a word.
So declare them as strings like this:std::string word1, word2,word3;
Length doesn't have to be declaredand you still have one if statement wrong. Please re-read …
Jump to Postline 1: you have to include <string> header file in order to use std::string class.
line 11: you still have the wrong operator -- should be ==, not =. Remember that = is an assignment operator while == is boolean.
All 20 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
lolodede
-2
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
lolodede
-2
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
lolodede
-2
Newbie Poster
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
lolodede
-2
Newbie Poster
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
ivailosp
11
Junior Poster
Traicey
10
Posting Whiz in Training
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
lolodede
-2
Newbie Poster
ivailosp
11
Junior Poster
lolodede
-2
Newbie Poster
ivailosp
11
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.