Can\'t get this to compile and run, am I doing something wrong? #include <iostre
ID: 662502 • Letter: C
Question
Can't get this to compile and run, am I doing something wrong?
#include <iostream.h>
//#include<conio.h>
//main method
int main()
{
int i, j, k, n;
int height,width;
//get trunk height
cout << "enter trunk Height: ";
cin >> height;
// get trunk Width
cout << " Enter trunk width:";
cin >> width;
// get leaves width
cout << " Enter leaves width:";
cin >> n;
//print the triangle pattern
for (i=1;1<=(n/2)+1;i++)
{
for(j=i;j<(n/2)+1;j++)
{
cout << " ";
}
for(k=1;k<(i*2);k++)
{
cout << "*";
}
cout << " ";
}
}
//print the rectangle pattern
for(i=0;i<height;i++)
{
cout << " ";
for (j=0;j<width;j++)
{
cout << "*";
}
}
return 0;
}
Explanation / Answer
In your program use "n" in the place of "n/2" in the first for loop.
The code for printing the triangle pattern is as follows, use this code for printing the triangle pattern :
And for printing the rectangle modify your code as follows:
for(i=0;i<=height;i++)
{
cout << " ";
for (j=0;j<=width;j++)
{
cout << "*";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.