I just learned c++ and is very hard for me to put in practice what I learned.
So, I would like to know if anybody could help me by giving me tasks and helping me to solve them.
Thanks
eduard77
-3
Junior Poster
Recommended Answers
Jump to PostPlease show the full contents of your input file, as well as exactly what the program prints when you run it. Do not try to interpret or explain what the program does. Just the facts, please.
Jump to PostIf your program reads only the first word, it is impossible to get the shortest and longest word, because you have no way of knowing what those words are.
Jump to PostBy doing something similar to what you did for the longest word?
if(count < shortest_word) { shortest_word = count; short_posi = i; }
Start longest and shortest initially as the length of the first word. If you have shortest_count = 1 then it's going to be tough …
Jump to PostThink about it, you can find the shortest and the longest all in one pass. Name your variable that marks the position of the shortest word as something different so it doesn't overwrite the one for the longest word.
Jump to PostLine 56, rename posi to posi_short or something, as it's overwriting the value of posi that you found for the longest word in the previous for loop.
I was just saying that you don't need a second for loop to test for the shortest value:
for( …
All 40 Replies
arkoenig
340
Practically a Master Poster
eduard77
-3
Junior Poster
eduard77
-3
Junior Poster
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
eduard77
-3
Junior Poster
eduard77
-3
Junior Poster
arkoenig
340
Practically a Master Poster
eduard77
-3
Junior Poster
arkoenig
340
Practically a Master Poster
eduard77
-3
Junior Poster
arkoenig
340
Practically a Master Poster
eduard77
-3
Junior Poster
arkoenig
340
Practically a Master Poster
eduard77
-3
Junior Poster
eduard77
-3
Junior Poster
arkoenig
340
Practically a Master Poster
eduard77
-3
Junior Poster
arkoenig
340
Practically a Master Poster
eduard77
-3
Junior Poster
arkoenig
340
Practically a Master Poster
eduard77
-3
Junior Poster
arkoenig
340
Practically a Master Poster
eduard77
-3
Junior Poster
arkoenig
340
Practically a Master Poster
eduard77
-3
Junior Poster
arkoenig
340
Practically a Master Poster
eduard77
-3
Junior Poster
eduard77
-3
Junior Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured 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.