C++ Triangle making.
#1

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:
*
**
***
****
*****
******
Reply
#2

*BUMP* please i need this urgently...
Reply
#3

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

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

@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;
}
Reply
#6

Thanks man ! rep for you ^^
Reply
#7

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

My school uses DevC++ for that shits
Reply
#9

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


Forum Jump:


Users browsing this thread: 1 Guest(s)