I need help in writing a project in which dimensions are read in for different shapes and I need to output these shapes next to each other with same boundaries based on user input. I have no difficulty in making the shapes, but in printing them out next to each other horizontally.
Here is my code:
#include<iostream>
using namespace std;
int main()
{
//Declare variables
int numStars, length, width, numRuns, numTimes;
char shapeType;
cin>>numRuns;
cout<< endl;
//Loop for all runs
for(int b=1; b<=numRuns; b++)
{
cout<<"Please enter box type and dimensions: ";
cin>> shapeType;
//Rectangle shape
if (shapeType=='B' or shapeType=='b')
{
cin>>width>>length>>numTimes;
for (int i=0; i<length; i++)
{
for (int a=0; a<width*numTimes-1; a++)
{
cout<<"* ";
}
cout <<endl;
}
}
//Triangle shape
if (shapeType=='L' or shapeType=='l')
{
cin>> numStars>>numTimes;
for(b=0; b<=numTimes; b++)
{
for (int a=1; a<=numStars; a++)
{
for(int j=1; j<=a; j++)
{
cout<<"* ";
}
cout<<endl;
}
}
}
//Square shape
if(shapeType== 'S' or shapeType== 's')
{
cin>>numStars;
Please put your code sample in code tags and provide input/output samples to indicate what you mean. (You can use the format menu to maintain fixed spacing.)
If you are putting several shapes adjacent to each other horizontally you may find it easier to create them on a “canvas” made up of an array of strings, one for each line. At the end you print out the canvas.
@OP Here's a start - note the extra j-loop for a box. You also need some prompts instead of a blinking cursor so the end-user to knows what is going on.