Solved

Needs help in logic

Posted on 2011-02-22
6
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

710 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