SA-MP Forums Archive
C++ Triangle making. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: C++ Triangle making. (/showthread.php?tid=382923)



C++ Triangle making. - Wayn - 05.10.2012

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:
*
**
***
****
*****
******


Re: C++ Triangle making. - Wayn - 05.10.2012

*BUMP* please i need this urgently...


Re: C++ Triangle making. - Sinner - 05.10.2012

Код:
#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.


Re: C++ Triangle making. - Wayn - 05.10.2012

Код:
#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:
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*


Re: C++ Triangle making. - Jessyy - 05.10.2012

@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 …
Quote:
Originally Posted by Sinner
Посмотреть сообщение
Код:
#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;
}



Re: C++ Triangle making. - Wayn - 05.10.2012

Thanks man ! rep for you ^^


Re: C++ Triangle making. - Mr.Anonymous - 05.10.2012

I'm sorry to reply here, but what program do you use to code in C++? I know Turbo C++ though.


Re: C++ Triangle making. - TheArcher - 05.10.2012

My school uses DevC++ for that shits


Re: C++ Triangle making. - Jessyy - 06.10.2012

I'm using the same program like @TheArcher ... Dev-C++ http://www.bloodshed.net/devcpp.html