Solved

Needs help in logic

Posted on 2011-02-22
6
378 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
Comment Utility
change asterisks <= 3 to asterisks <= row
0
 

Author Comment

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

Expert Comment

by:TommySzalapski
Comment Utility
replace asterisks <= row with asterisks <= (4-row)
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 37

Accepted Solution

by:
TommySzalapski earned 400 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 71
bigHeights  challenge 13 55
My 2003 Land Rover discovery 2 key for code for car alarm 7 78
algorithm 15 74
This is an explanation of a simple data model to help parse a JSON feed
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.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

771 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

10 Experts available now in Live!

Get 1:1 Help Now