Sorry my code is sloppy and poorly formatted. I haven't touched C++ in a while. I think this is what you're looking for though.
Code
#include <iostream>
int main ()
{
char choice;
int leftOrRight;
int distanceFromEdge;
while(true){
std::cout << "Press 't' for triangle or 'r' for rectangle: ";
std::cin >> choice;
std::cout <<"1 or -1";
std::cin >>leftOrRight;
int lengthOfSides=0;
std::cout << "Length of sides?: ";
std::cin >> lengthOfSides;
std::cout<<"Distance from edge?: ";
std::cin >> distanceFromEdge;
if(choice=='t'){
if(leftOrRight==1){
for (int i=1; i<=lengthOfSides; ++i){
{
for(int k=0;k<distanceFromEdge;k++) std::cout<<" ";
for(int j=0; j<lengthOfSides-i;j++){
std::cout<<" ";
}
for(int j=0;j<i;j++){
std::cout<<"*";
}
std::cout << "\n";
}
}
} else if(leftOrRight==-1){
for (int i=1; i<=lengthOfSides; ++i){
for(int k=0;k<distanceFromEdge;k++) std::cout<<" ";
for(int j=1; j<=i;j++){
std::cout<<"*";
}
std::cout << "\n";
}
}
}
else if(choice=='r'){
for(int i = 0; i < lengthOfSides;i++){
for(int k=0;k<distanceFromEdge;k++) std::cout<<" ";
for(int j = 0; j < lengthOfSides;j++){
std::cout<<"*";
}
std::cout<<"\n";
}
}
else{
std::cout<<"Invalid input\n";
continue;
}
}
return 0;
}
This post was edited by labatymo on Mar 28 2013 07:52am