Create a cross word C++

Asked

Viewed 198 times

0

ArmandoWho could help me with this?

Let me give you an example of what I want.

A     A
 R   R
  M M
   A
  N N
 D   D
O     O

But the same spaces have to be horizontal, as vertical, has to be square.

Thank you

  • Is this a college exercise or something?

  • Does it have to be C++ or can it be C? Is there any other kind of restriction, such as specific classes or functions to use or not to use or some kind of structure that the program has to follow? Or anything that the compiler accepts and produces that result is worth?

  • I have to do this in c++I’m trying to do with for, qq help is welcome, even if it is in another language I already realized I have to do the counting by lines and the separation by char... but I’m not there to xegar.

  • My suggestion is to first try to make one of the propellers of the cross, then the other, and then combine the two. Note for example that on the first helix, there are 0 spaces before character 0, 1 space before character 1, and so on. In the second, there are (size-1) spaces before character 0, (size-2) before character 1, etc. Another way to think is that there is an array of blank spaces ("length" lines and "size" columns), and the letter N occupies both column N and size-N-1 on line N. Start printing only the spaces, then use ifs to choose between a space and a letter.

  • Is this printed in the terminal? Or in a GUI? Please provide details.

  • In terminal CMD, I’ll leave the printscreen here

  • @Rubenpais this should be informed in the question, edit it and specify this :)

  • Thank you @Guilherme Nascimento .... but I have already decided... but next time I will take this into account . Thank you

Show 3 more comments

2 answers

3

That will do?

#include <iostream>
#include <string>
using namespace std;

int main() {
    const string c = "ARMANDO";
    int t = c.length() - 1;
    for (int i = 0; i <= t; i++) {
        for (int j = 0; j <= t; j++) {
            cout << (i == j || i == t - j ? c[i] : ' ');
        }
        cout << '\n';
    }
}

The trick is that i == j is the main diagonal and i == t - j is the secondary diagonal.

1

I, yesterday at the end of much fight I managed.

I want to thank everyone who helped and gave me ideas.

Thank you.

I leave here the resolution.

#include <iostream>
#include <string>

using namespace std;

int main(){
    cout << "Introduza nome: ";
    string name;
    getline(cin, name);


    for(int line = 0; line < name.size(); line++){
        for(int space=0; space < name.size();space++){
            if(space == line){
                cout << name[line];
            }
            else{
                if(space == name.size()-line-1){
                    cout << name[line];
                }
                else{
                    cout << " ";
                }
            }
        }   
        cout << endl;
    }
    return 0;
}

RESULTADO

Browser other questions tagged

You are not signed in. Login or sign up in order to post.