Modify the program in step 2 so that if the
x-coordinate (the number of *'s you print on a line)
for any line falls within the range 20 ≤ x ≤ 30 then
only print a line with exactly 20 *’s rather than the
calculated value of x. This will make a sharp vertical
cliff in the triangle for some number of lines (maybe
none if theta is small) and then resume along the
original diagonal line. Compile and test your
program.
Can anyone help me to figure out how to do this part.
I am supposed to get this:
*
***
*****
******
********
**********
************
*************
***************
*****************
*******************
********************
********************
********************
********************
********************
********************
*******************************
********************************
**********************************
************************************
**************************************
***************************************
*****************************************
*******************************************
*********************************************
**********************************************
************************************************
**************************************************
but insted I am getting this:
*
***
*****
******
********
**********
************
*************
***************
*****************
*******************
********************
********************
********************
********************
********************
********************
**********************
***********************
*************************
***************************
*****************************
******************************
********************************
**********************************
************************************
*************************************
***************************************
*****************************************
******************************************
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <iostream>
#include <string>
#include <cmath>
#define PI 3.14159265
using namespace std;
int main()
{
char star = '*';
int rows = 31;
int angle_theta = 0;
int length = 1;
cout <<"Enter angle between 15 - 75: ";
cin >> angle_theta;
cout << "Entered theta " << angle_theta << " degree" << endl;
for(int i = 1; i < rows; i++)
{
//cout << "number of i " << i << endl;
//length = i * floor(tan(angle_theta*PI/180.0));
length = floor(i * tan(angle_theta*PI/180.0));
//cout << "length " << length;
for(int j = 0; j < length; j++)
{
if( j >= 0 && j <= 19)
cout << star;
else if( j >= 29 )
cout << star;
else if ( j >= 19 && j <= 29)
cout << "";
}
cout << endl;
//length++;
}
return 0;
}
|