🔒 Locked
simple C++ shapes
Advertisement
Original Post
opengl, directx, gdi, gdi+?
Here is the code I used for the isosceles triangle:
void filled_iso ()
{
int b; //////b=base
cout << "Please enter the size of the base for your isosceles (must be odd): ";
cin >> b;
if (b<0 || b>80 || b%2 !=1)
{
cout<<"The size of the base must be and odd number greater than zero and less than 80!\n";
cin>> b;
}
for (int j = 0; j < b/2 + 1; j++)
{
// for (int i = 0 ; i < 2 * j + 1; i++)
int temp1 = j * 2 + 1;
int temp2 = (b - temp1);
int disp = (temp2 / 2);
for (int i = 0 ; i < b; i++)
{
if ((i < disp) || (i > b - disp -1 ))
cout << " ";
else
cout << "*";
}
cout << endl;
}
}
I need a code similar to draw an unfilled isosceles triangle and a right triangle
void filled_iso ()
{
int b; //////b=base
cout << "Please enter the size of the base for your isosceles (must be odd): ";
cin >> b;
if (b<0 || b>80 || b%2 !=1)
{
cout<<"The size of the base must be and odd number greater than zero and less than 80!\n";
cin>> b;
}
for (int j = 0; j < b/2 + 1; j++)
{
// for (int i = 0 ; i < 2 * j + 1; i++)
int temp1 = j * 2 + 1;
int temp2 = (b - temp1);
int disp = (temp2 / 2);
for (int i = 0 ; i < b; i++)
{
if ((i < disp) || (i > b - disp -1 ))
cout << " ";
else
cout << "*";
}
cout << endl;
}
}
I need a code similar to draw an unfilled isosceles triangle and a right triangle
Me thinks he is refering to console (prompt) graphics?
Quote:
Original post by srocky26
I'm using windows xp with visual c++. All I have to make is something like this.right triangle - - *- **- * *- * *- *****isosceles triangle - - *- * *- * *- *******
Quote:he is.
Original post by Pipo DeClown
Me thinks he is refering to console (prompt) graphics?
Quote:
Original post by RLigon
could this be a homework problem? ;)
goes with out saying, don't you think?
in any case, a little help won't hurt.
Simplify the problem!
Make the first and last lines special cases.
The first line is only a single * in the center or on the far left. That is easy.
The last line is all stars. That is also easy.
All the lines inbetween are [k spaces]*[i spaces]*[k spaces]
If i goes from 0 to width of base - 2, then all you need to is set k equal to the width of the base - i - 2
Make the first and last lines special cases.
The first line is only a single * in the center or on the far left. That is easy.
The last line is all stars. That is also easy.
All the lines inbetween are [k spaces]*[i spaces]*[k spaces]
If i goes from 0 to width of base - 2, then all you need to is set k equal to the width of the base - i - 2
Quote:
Original post by srocky26
yeah, it is homework, ive been working on it for about 3 hours, trying to find a way to do it, but i can't figure it out :(
Only 3 hours? That's not too much [smile] We don't give much help with homeworks here...
But I'll throw something in. When drawing an unfilled right triangle - normally it's filled with '*', right? So, what about drawing the triangle like it was filled, but printing ' ' (a space), instead of '*' when you're not printing out first / last asterisk on the given line?
Oxyd
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement