We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,386 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Help with generating a code

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:

            &
          &   &
        &       &
      &           &
    & & & & & & & & &
7
Contributors
8
Replies
3 Days
Discussion Span
8 Months Ago
Last Updated
10
Views
Manojpandey96
Newbie Poster
3 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Post your hard work, I'll give you a hand finding the problem.
but am I wrong to assume you have nothing to post?

Despairy
Junior Poster
123 posts since Mar 2011
Reputation Points: 10
Solved Threads: 5
Skill Endorsements: 0

first you show some code then only we can help you

vinnitro
Posting Pro
536 posts since Sep 2010
Reputation Points: 7
Solved Threads: 4
Skill Endorsements: 7

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).

Bob
using namespace Bob
Team Colleague
221 posts since Feb 2003
Reputation Points: 30
Solved Threads: 11
Skill Endorsements: 0

You cant just use gotoxy(num, anothernum); and increment or decrement them in the for(int i) loop??

zvjezdan.veselinovic
Light Poster
35 posts since Sep 2012
Reputation Points: -3
Solved Threads: 3
Skill Endorsements: 0

You cant just use gotoxy(num, anothernum); and increment or decrement them in the for(int i) loop??

What if gotoxy() isn't supported by the compiler?

deceptikon
Challenge Accepted
Administrator
3,457 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 57

Try to make a general formula for printing 'spaces' and '&'.

For example :

  1. 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 ).

Try this and post your work.
Hope this helps :-)

np complete
Posting Whiz
385 posts since Sep 2010
Reputation Points: 18
Solved Threads: 36
Skill Endorsements: 0

do

#include <conio.h>
#include <windows.h>

This is what I did for my Tic-Tac-Toe Game in C++. These 2 lines helped me create gotoxy and resize screen with

system("mode num,another_num");
zvjezdan.veselinovic
Light Poster
35 posts since Sep 2012
Reputation Points: -3
Solved Threads: 3
Skill Endorsements: 0

do
#include <conio.h>
#include <windows.h>

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.

deceptikon
Challenge Accepted
Administrator
3,457 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 57

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0855 seconds using 2.75MB