PDA

View Full Version : C++ Triangle making.


Wayn
05/10/2012, 05:53 PM
so i decided to make a code where i can make a TRIANGLE using only one "*" (staric character) for loops.i dont want to simply print multiple sterrics by myself. so please tell me what is wrong with my code?
#include <iostream>

using namespace std;

int main()
{
int i,j;
for(i=1;i<=6;++i)
{
for(j=1;j<=6;++j)
cout<<"*";
cout<<endl;

}
return 0;
}



The result should be like this:
*
**
***
****
*****
******

Wayn
05/10/2012, 06:05 PM
*BUMP* please i need this urgently...

Sinner
05/10/2012, 06:11 PM
#define TRIANGE_SIZE 6
int main() {
int start = 1;
while(start != TRIANGLE_SIZE) {
for(new i=0; i<start; i++) {
cout<<"*";
cout<<endl;
}
start++;
}
}


You should make your homework yourself though.

Wayn
05/10/2012, 06:45 PM
#define TRIANGLE_SIZE 6
using namespace std;

int main() {
int start = 1;
while(start != TRIANGLE_SIZE) {
for(int i=0; i<start; i++) {
cout<<"*";
cout<<endl;
}
start++;
}
}

used this, changed the 'new' to 'int' but no luck
this is my output using this:
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

Jessyy
05/10/2012, 07:09 PM
@Wayn: Try this ...

#include <iostream>
using namespace std;

#define SIZE 10

int main()
{
int i,j;

for(i=1; i<=SIZE; ++i) {
for(j=1; j<=i; ++j) cout<<"*";
cout<<endl;
}

system("pause");
return 0;
}



Output:

*
**
***
****
*****
******
*******
********
*********
**********


i - represent the line nr [from 1 to SIZE]
j - how many "*" whill show [from 1 to i (the nr of "*" ar the same whit the line nr) ]


@Sinner: Your ideea is good but

#define TRIANGE_SIZE 6
int main() {
int start = 1;
while(start != TRIANGLE_SIZE) {
for(new i=0; i<start; i++) {
cout<<"*";
cout<<endl;
}
start++;
}
}

The output of your code will be ...

*
*
*
*
*
*
*
*
*
*
*
*
*
*
*


Your code shut be ...

#include <iostream>
using namespace std;

#define TRIANGLE_SIZE 6

int main()
{
int start = 1;
while(start != TRIANGLE_SIZE) {
//for(new i=0; i<start; i++) { //will show "TRIANGLE_SIZE - 1" lines whit "*"
for(int i=0; i<=start; i++) { //will show "TRIANGLE_SIZE" lines whit "*"
cout<<"*";
//cout<<endl;
}
cout<<endl; //this is the place where shud be
start++;
}

system("pause");
return 0;
}

Wayn
05/10/2012, 07:24 PM
Thanks man ! rep for you ^^

Mr.Anonymous
05/10/2012, 08:48 PM
I'm sorry to reply here, but what program do you use to code in C++? I know Turbo C++ though.

TheArcher
05/10/2012, 08:51 PM
My school uses DevC++ for that shits :D

Jessyy
06/10/2012, 11:39 AM
I'm using the same program like @TheArcher ... Dev-C++ http://www.bloodshed.net/devcpp.html