Introduction: Create Shapes in C++

Picture of Create Shapes in C++

Ever wondered to create different shapes using c++, well this is the instructable you are looking for......

IN THIS INSTRUCTABLE WE WILL LEARN HOW TO CREATE DIFFERENT RIGHT TRIANGLE SHAPES......

Step 1: Materials Required

Picture of Materials Required

1) Only a c++ ide(integrated development environment)

2) some interest in c++

Step 2: The Code for It

Picture of The Code for It

I have used functions, switch statement and for loops in this code. If you want you can modify the code by adding some more shapes :)

THE CODE IS GIVEN BELOW :-

#include <iostream>
using namespace std; void rt1() { for(int i = 0; i < 5; i++) { for(int k = 0; k <= i; k++) { cout<<"*"; } cout << endl;

}

}

void rt2()
{ for(int i = 5; i > 0; i--) { for(int k = 0; k <= 5; k++) { if( k < i) cout<<" "; else if( k >= i) cout<<"*"; } cout<<endl;

}

}

void rt3()
{ for(int i = 5; i > 0; i--) { for(int k = 0; k <= 5; k++) { if( k < i) cout<<"*"; else if( k >= i) cout<<" "; } cout<<endl;

}

}

void rt4()
{ for (int a = 5; a > 0; a--) { for (int k = 0; k < 5 - a; k++) { cout<<" "; }

for(int b = 1; b <= a; b++) { cout<<"*"<<" "; }

cout<<endl;

}

}

int main()
{ int a; cout<<" enter a number between 1 - 4 to see different shapes "; cin >> a;

switch(a)

{ case 1: rt1(); break; case 2: rt2(); break; case 3: rt3(); break; case 4: rt4(); break; default: cout<<"invalid entry"; break; } }


Step 3: Compiling and Running

Picture of Compiling and Running

Now just compile and run the code and have fun

<<<<ENJOY>>>>

Comments

About This Instructable

162views

2favorites

License:

Bio: I am a computer programmer and electronics enthusiast and want to develop a world full of programmers because " PROGRAMMERS NEVER DIE ".
More by KushalS24:create shapes in c++How to delete everything in a pc with a clickoperators in c++
Add instructable to: