C++ HELP!!!

Hi, all! :)

HELP, I need help.. So- my task:

I have to enter 5 different words in my c++ program, then define the length and THEN output those words (from those 5 which I defined) which is similar with the length I defined. Maybe I explained difficult.. here's the example -->

-> user types 5 words: apple, bag, pineapple, crocs, x THEN user types a length, like 5 and THEN there is an output: apple, crocs. (Because other words length is not 5)

THANK YOU!!!! :)))
If your teacher lets you use std::string instead of char arrays, that will make the program a bit more elegant.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <cstddef> // for std::size_t
#include <iostream> // for std::cin, std::cout
#include <string> // for std::string

// ...

std::string words[5]; // an array of five strings
std::size_t desired_length = 0; // what length are we searching for?

std::cin >> desired_length;

for (/* loop five times, to read into the words array */)
    std::cin >> words[i];

for (/* loop five times again to check lengths */)
    if (words[i].length() == desired_length)
        // print words[i] 
Last edited on
Okey.. thank You! I will try to get this work.
Topic archived. No new replies allowed.