2 Replies - 968 Views - Last Post: 10 March 2012 - 03:33 AM Rate Topic: -----

#1 dula  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-March 12

problem-how to print the following triangle

Posted 10 March 2012 - 01:52 AM

I want to print the following triangle
*
**
***
I couldn't get it done with this C++ code.
#include<iostream>
using namespace std;
int main()
{
    for(int i=0;i<3;i++)
   {for(int j=0;j>=-x;j--)
      cout<<"*";
    }
    return 0;
}


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 10 March 2012 - 03:50 AM


Is This A Good Question/Topic? 0
  • +

Replies To: problem-how to print the following triangle

#2 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 208
  • View blog
  • Posts: 552
  • Joined: 12-July 09

Re: problem-how to print the following triangle

Posted 10 March 2012 - 02:38 AM

You have to print a newline after each line:
cout << '\n';
//or
cout << endl;

Was This Post Helpful? 0
  • +
  • -

#3 jdavi134  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 225
  • Joined: 26-October 11

Re: problem-how to print the following triangle

Posted 10 March 2012 - 03:33 AM

I'm also confused about something. How are you not getting an error saying that variable x has not been declared? Unless I missed something, you never give that variable a value or even declare it.

And another thing. If you are just trying to print out that basic triangle, why are you using 2 loops? You only need one.

Jack
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1