Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Needs help in logic

Posted on 2011-02-22
Medium Priority
388 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
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

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

Author Comment

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

LVL 37

Expert Comment

ID: 34956859
replace asterisks <= row with asterisks <= (4-row)
0

LVL 37

Accepted Solution

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

LVL 32

Assisted Solution

phoffric earned 400 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

ID: 34957353
Thanks.
0

## Featured Post

Question has a verified solution.

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

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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is â€“ how do I become a web developer?
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
###### Suggested Courses
Course of the Month7 days, 4 hours left to enroll

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

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