Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- //Created by Tim Howard
- void draw_square(int w)
- {
- for(int row = 1; row <= w; row++)
- {
- cout<<"*"; //prints the first column of the square
- for(int column = 1; column <= (w-2); column++)
- {
- if(row == 1 || row == w) //prints the top and bottom of the square
- {
- cout<<"*";
- }
- else
- {
- cout<<" ";
- }
- if(column == (w-2)) //prints the sides of the square
- {
- cout<<"*";
- }
- }
- cout<<endl;
- }
- }
- void draw_Square(int w, int h)
- {
- for(int row = 1; row <= w; row++)
- {
- cout<<"*"; //prints the first column of the square
- for(int column = 1; column <= (h-2); column++)
- {
- if(row == 1 || row == w) //prints the top and bottom of the square
- {
- cout<<"*";
- }
- else
- {
- cout<<" ";
- }
- if(column == (h-2)) //prints the sides of the square
- {
- cout<<"*";
- }
- }
- cout<<endl;
- }
- }
- int main()
- {
- char restart = 'y';
- int choice;
- int width;
- int height;
- int shift;
- cout << "Welcome to the Shape Creator program\n";
- cout << "Would you like to make a square, rectangle or a shifted rectangle?\n"
- << "Enter 1, 2, or 3: ";
- cin >> choice;
- if (choice == 1)
- {
- do{
- cout << "Please enter the width of your square: ";
- cin >> width;
- draw_square (width);
- cout << "Would you like to restart the program? Y or N: ";
- cin >> restart;
- }while (restart == 'y' || restart == 'Y');
- }
- else if (choice == 2)
- {
- do{
- cout << "Please enter the width and height of your rectangle, separated by a space: ";
- cin >> width, height;
- draw_Square (width, height);
- cout << "Would you like to restart the program? Y or N: ";
- cin >> restart;
- }while (restart == 'y' || restart == 'Y');
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement