Solved

Needs help in logic

Posted on 2011-02-22
6
379 Views
Last Modified: 2012-05-11
Hi guys: Can any one please help me how to i print the * in that order that first it print one then two and then three. I try it first but made mistakes as its printing three in each row

Output required
*
**
***

#include <iostream>
using namespace std;

int main()
{
      for (int row = 1; row < 4; row +=1)
      {
            for(int asterisks = 1; asterisks <= 3; asterisks +=1)
                  cout << '*';
      cout << endl;
      }
      system("pause");
      return 0;
}
0
Comment
Question by:mustish1
  • 3
  • 2
6 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34956708
change asterisks <= 3 to asterisks <= row
0
 

Author Comment

by:mustish1
ID: 34956720
Thanks. just last thing how to i reverse it means
***
**
*
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34956859
replace asterisks <= row with asterisks <= (4-row)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 37

Accepted Solution

by:
TommySzalapski earned 400 total points
ID: 34956862
See how that works? As row gets higher, now the max value gets lower.
0
 
LVL 32

Assisted Solution

by:phoffric
phoffric earned 100 total points
ID: 34957304
It may be a little less confusing if you define a function, print_row_of_asterisks(int numberOfAsterisks), and just call that function in a single loop. The loop inside the function should then be easy to figure out.

Also, the code will look a lot cleaner.
0
 

Author Closing Comment

by:mustish1
ID: 34957353
Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordappend challenge 8 149
Adding Namespace to the second node of the xml 16 64
Path to Python 9 107
Advice on Xojo as a development tool over VB. 4 39
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now