Can someone help me with writing C++ program using loop for the following fragment..
I tried damn hard to do so, but nothing i achieved.
The fragment looks like this:
& & & & & & & & &
8 Months Ago
Related Article:Visual Studio runs code from another file
is a solved C++ discussion thread by StickyTape that has 18 replies, was last updated 1 year ago and has been tagged with the keywords: c++, code, compile, problem, studio, visual.
Consider the algorithm you need to apply to achieve this. Express the steps in natural language first, to get it straight in your mind. When you think you have that sorted, try coding the steps. If you can't get your code to work, post it here.
You know you need a main() function. You know you need a loop of some kind. You know that inside the loop you need some form of output statement.
If you look at the desired output, some lines have different characteristics from others, so you need to cater for this in your output statement(s).
Try to make a general formula for printing 'spaces' and '&'.
For example :
The number of spaces that are to be printed in 1st line (outside the triangle) is one less than the number of lines given by user. It decreases by 1 as we move from one line to another.
Divide your task, which means, keep one loop that increments line, one that prints spaces outside the triangle, one that prints inside the triangle, and one that prints &
Also here is a hint : Try to print last line separately, that is outside loops that prints the upper part ( in your example, lines (1 - 4) means upper part, so lines (1 - 4) and 5 to be done separately ).
The rest of the world may not use the same compiler and OS as you do. Both conio.h and windows.h are dependent on the implementation. Further, this problem can be solved without resorting to non-portable libraries. You don't have to call gotoxy() when it's a simple matter of printing a few space characters.