I have just started a short C++ course and gotten stuck in the creation of the pattern shown below which is a right angle triangle of dots within a rectangle of stars using nested looping techniques:
I would be very grateful for someones help in this matter as it is driving me absolutely bonkers lol, I have been looking at the screen since 12 o clock last night it is now 8.11 am please help me
The display is now coming up as correct all except for the last line where I now wish to have a line of 8 stars. Would it be considered bad coding to simply put the 8 stars on a new line via the cout << function ?
I would appreciate it if someone would be able to help me in understanding this problem. Also I would appreciate it if you would tell me if it would be considered bad coding to simply place in the last line of stars to complete the display.
Well...if you don't need to use loops, I would just cout the whole thing, but I assume you are required/want to do it that way.
What I would do is just always print out one * in the beginning, then find out how many spaces (if any) I need to print, then make the rest *s, using a const int to check how many spaces/*s should be on one line.
I doubt it would be considered bad coding, since there seems to be no other way to print 8 *s on the screen. You can use another for loop though, but that would be kind of useless.
1 2
for(int j=0;j<8;j++)
cout<<'*';
PS: Why exactly are you using C-style programming in C++? int i,k,q;
its better to declare the variables when you need them, it makes the code more understandable.