7 Replies - 4131 Views - Last Post: 09 May 2013 - 04:28 PM Rate Topic: -----

#1 mel143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-May 13

C++ asterisk pyramid program flowchart

Posted 09 May 2013 - 10:48 AM

I understand the below code will output a pyramid that has an odd number of asterisks on each line, however I'm trying to convert this to a flowchart in Visual Basic. The for loops are what's confusing me and how to get the number of spaces and asterisks correct per line. Any help is greatly appreciated!

// Stars(asterisk) pyramid perfectly packed into each space.
#include<iostream>
using namespace std;

int main()
{
   int count = 0;
   
   for (int width = 0; width <= 10; width++)
   {
      for (int alignLeft = width; alignLeft <= 15; alignLeft++)
      {
         cout << " ";
      }
      for (int space = 1; space < count; space++)
      {            
         cout << "*";                  
      }         
      cout << endl;
      count += 2;      
   }
   return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: C++ asterisk pyramid program flowchart

#2 mel143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-May 13

Re: C++ asterisk pyramid program flowchart

Posted 09 May 2013 - 11:06 AM

I totally meant a flow chart for Visual Logic, not Basic. Also, I understand how to set up the min, max, and steps. I'm just confused on where to put the algorithms for the number of asterisks and spaces to be printed. I know asterisks = 2*(user input for number of lines) - 1 and spaces = user input for lines - 1

View Postmel143, on 09 May 2013 - 10:48 AM, said:

I understand the below code will output a pyramid that has an odd number of asterisks on each line, however I'm trying to convert this to a flowchart in Visual Basic. The for loops are what's confusing me and how to get the number of spaces and asterisks correct per line. Any help is greatly appreciated!

// Stars(asterisk) pyramid perfectly packed into each space.
#include<iostream>
using namespace std;

int main()
{
   int count = 0;
   
   for (int width = 0; width <= 10; width++)
   {
      for (int alignLeft = width; alignLeft <= 15; alignLeft++)
      {
         cout << " ";
      }
      for (int space = 1; space < count; space++)
      {            
         cout << "*";                  
      }         
      cout << endl;
      count += 2;      
   }
   return 0;
}


Was This Post Helpful? 0
  • +
  • -

#3 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: C++ asterisk pyramid program flowchart

Posted 09 May 2013 - 11:12 AM

Are you trying to make a literal flow chart? Or am I falling short of some information?
Was This Post Helpful? 0
  • +
  • -

#4 mel143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-May 13

Re: C++ asterisk pyramid program flowchart

Posted 09 May 2013 - 11:19 AM

View PostIngeniousHax, on 09 May 2013 - 11:12 AM, said:

Are you trying to make a literal flow chart? Or am I falling short of some information?


Here is a screenshot of what I have so far.

Posted Image
Was This Post Helpful? 0
  • +
  • -

#5 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: C++ asterisk pyramid program flowchart

Posted 09 May 2013 - 11:37 AM

Just design it exactly as you see your logic in the code. Here is a small thing I came up, only addresses the for loops.Posted Image
Was This Post Helpful? 0
  • +
  • -

#6 mel143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-May 13

Re: C++ asterisk pyramid program flowchart

Posted 09 May 2013 - 11:59 AM

View PostIngeniousHax, on 09 May 2013 - 11:37 AM, said:

Just design it exactly as you see your logic in the code. Here is a small thing I came up, only addresses the for loops.Posted Image


I wish I could do that because it would be so much easier. However, I must implement For Loops and not while loops within the flowchart. Also Visual Logic doesn't allow you to post test while loops. So that won't work. But thank you =)
Was This Post Helpful? 0
  • +
  • -

#7 malerv  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 100
  • Joined: 01-July 09

Re: C++ asterisk pyramid program flowchart

Posted 09 May 2013 - 02:02 PM

I would represent this
for (x = 0; x < n; x++)
{
   print("toto");
}



like this
 x = 0
   |
   <--------------------------------
   |                                 |
(x < n) -no--> print("toto") x++ ----
   |
   yes
   |




Sorry I have no graphique software

This post has been edited by malerv: 09 May 2013 - 02:08 PM

Was This Post Helpful? 0
  • +
  • -

#8 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1327
  • View blog
  • Posts: 4,552
  • Joined: 19-February 09

Re: C++ asterisk pyramid program flowchart

Posted 09 May 2013 - 04:28 PM

Just before the spaces for loop you can calculate the number of spaces.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1