d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Paying Fg For 20 Minutes Of Your Time > Just Need Pseudocode To Get Me Goin C++
Add Reply New Topic New Poll
Member
Posts: 6,175
Joined: Jun 22 2005
Gold: 12,542.29
Mar 27 2013 11:41pm
heres basically all im looking for.
i need to make a program that makes triangles and rectangles out of asterisks (*).
the user will imput T for triangle or R for rectangle and then either 1 or -1, indicating whether the triangle goes to the left or right.
then the 2nd number telling the length of the sides, and the third number indicating the position of the triangle with respect to the left (i.e. the number of blanks before the triangle starts).
for anyone that has taken 1 or more programming classes in C++, this really shouldnt take long at all (easily under an hour).
i just havent been going to class and need a head start on where to go.

if you want the full set of directions to what needs to be done plz pm me asap (its not much more directions than what was already stated).
Member
Posts: 1,436
Joined: Jul 7 2006
Gold: 994.00
Mar 28 2013 06:25am
Please read your inbox hellomoto13 and I'm sure you'll learn from my solution. If the code is not self explanatory you can lend me a pm.
Oh, and if you feel like sharing it you could post the code here :)
Member
Posts: 2,478
Joined: Jan 4 2007
Gold: 7,545.00
Mar 28 2013 06:37am
Well since this is for homework, I would strongly recommend attempting this first and then asking us more specific questions.

You're only going to fall further behind the more you procrastinate like this.
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Mar 28 2013 07:44am
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
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll