#creating a tower of box numbers

32 messages · Page 1 of 1 (latest)

winter spruce
#

so the problem asks me to make a tower of box numbers like the image example only using while and if.
i kinda got the code but got stuck and dont know how to continue sadcatup plz help

pisos = floors, filas = lines and clu = columns, contapisos = countfloors

#include "pch.h"
#include "iostream"
using namespace System;
using namespace std;

int main() {
    int Pisos;
    int filas = 1, clu = 1, elimite = 8, n = 4, Contapisos = 0;
    int e = 1;
    int x, y = 0;
    int num = 1;
    do {
        cout << "Ingrese un número del 1 al 5: "; cin >> Pisos;
    } while (!(Pisos <= 5 && Pisos >= 1));
    while (Contapisos < Pisos) {

        while (filas <= n)
        {
            while (clu <= n)
            {
                while (e < elimite) //generar espacios
                {
                    cout << " ";
                    e++;
                }

                if (filas == 1 || filas == n || clu == 1 || clu == n)
                {
                    cout << num;
                }
                else { cout << " "; }

                if (num >= 2) {
                    n = 3;
                    if (filas == 1 || filas == 4 || clu == 4 || clu == n)
                    {
                        cout << num;
                    }
                    else { cout << " "; }
                }
                n = 4;
                clu++;
               
                _sleep(50);
            }
            e = 1;
            clu = 1;
            filas++;
            cout << endl;
        }
        Contapisos++;
        filas = 1, clu = 1;
        elimite = elimite - 2;
        e = 1;
        num++;
    }
    return 0;
}
onyx pantherBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

ember totem
#

you need to calculate how much leading ' ' characters to print according to the level you are on currently

#

for the 22222222 lines

#

and for the 2 22 2 lines

#

do you know how to write functions?

winter spruce
ember totem
#

you can see that the max line length is n*n

#

a.k.a. 16

winter spruce
rocky solar
winter spruce
ember totem
#

well, double quotes still work

#

doesn't matter

rocky solar
#

Oh cool

winter spruce
#

wait im so lost. what do i put in the function uwah like just the void square(int Pisos, int filas, int n, int clu) ?

ember totem
onyx pantherBOT
ember totem
onyx pantherBOT
ember totem
#

@winter spruce did you see my solution?

winter spruce
#

yes im reading it rn

#

the padding part is like the spaces before the square is printed right?

#

ohh wait i think i got it POGGERS

#

thankyou so much !

onyx pantherBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

ember totem