Solved

Needs help in logic

Posted on 2011-02-22
6
381 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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 …

813 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

11 Experts available now in Live!

Get 1:1 Help Now