0

someone could help me I have to make a z with the numbers 1-10 in the program in c ++

https://code.sololearn.com/ch4Z8957Rg0D/?ref=app

12th Oct 2019, 5:43 AM
Fernanda C. A
Fernanda C. A - avatar
9 odpowiedzi
+ 1
This does something like what you need but not exactly as the output you show..but... best i could do. #include <iostream> #include <iomanip> // needed for the setw() using namespace std; int main() { int width = 4; for(unsigned int x = 1; x < 11; x++){ if(x < 5 || x > 8) cout << x; else cout << endl << setw(width--) << x; } return 0; }
12th Oct 2019, 9:35 AM
rodwynnejones
rodwynnejones - avatar
+ 1
Looking at the output of your code, it seems you need more than 1-10 to output a complete a letter Z here. How you decide the width and height of the letter Z? does it depend on user input?
12th Oct 2019, 6:41 AM
Ipang
+ 1
I'll try something out, I'll get back to you if I can work something out. In the meantime, you keep trying okay?
12th Oct 2019, 7:19 AM
Ipang
0
no, the program as such is just printing a "z" from 1 to 10, the width and height I decide
12th Oct 2019, 6:47 AM
Fernanda C. A
Fernanda C. A - avatar
0
Look at this please 12345 6 7 8 910111213 This is what I figure of a letter Z, but it takes more than 1-10, as we put 5 numbers as width, and also 5 numbers as height. If we use 1-10 then there will be only 2 numbers at the floor (9 and 10). I still don't know how to figure this out TBH : )
12th Oct 2019, 7:08 AM
Ipang
0
1234 5 6 78910 Thus reducing size is a z of 1-10. I was doing it with the for cycle, but I don't know how to give the spaces to accommodate the numbers that are impregnated
12th Oct 2019, 7:18 AM
Fernanda C. A
Fernanda C. A - avatar
0
Ok. Thank you
12th Oct 2019, 7:22 AM
Fernanda C. A
Fernanda C. A - avatar
0
Well, this one works particularly for number 1-10. I still haven't figured out a way to calculate the width & height, so I hard coded them as `size` in code. Maybe you can improve from this. #include <iostream> int main() { int size {4}, padding {2}; int n {10}; for (int i {1}; i <= n; i++) { if (i <= size || i > n - size) { std::cout << i; if (i == size) std::cout << std::endl; } else { for (int p {0}; p < padding; p++) { std::cout << " "; } std::cout << i << std::endl; padding--; } } return 0; }
12th Oct 2019, 8:59 AM
Ipang
0
Thank you
28th Oct 2019, 4:45 AM
Fernanda C. A
Fernanda C. A - avatar