Advertisement
Guest User

C++ Trouble

a guest
Oct 28th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5.  
  6. //Created by Tim Howard
  7.  
  8.  
  9.  
  10. void draw_square(int w)
  11. {
  12.     for(int row = 1; row <= w; row++)
  13.     {
  14.         cout<<"*"; //prints the first column of the square
  15.         for(int column = 1; column <= (w-2); column++)
  16.         {
  17.             if(row == 1 || row == w) //prints the top and bottom of the square
  18.             {
  19.                 cout<<"*";
  20.             }
  21.            
  22.             else
  23.             {
  24.                 cout<<" ";
  25.             }
  26.            
  27.             if(column == (w-2)) //prints the sides of the square
  28.             {
  29.                 cout<<"*";
  30.             }
  31.         }
  32.         cout<<endl;
  33.     }
  34.    
  35. }
  36.  
  37. void draw_Square(int w, int h)
  38. {
  39.     for(int row = 1; row <= w; row++)
  40.     {
  41.         cout<<"*"; //prints the first column of the square
  42.         for(int column = 1; column <= (h-2); column++)
  43.         {
  44.             if(row == 1 || row == w) //prints the top and bottom of the square
  45.             {
  46.                 cout<<"*";
  47.             }
  48.            
  49.             else
  50.             {
  51.                 cout<<" ";
  52.             }
  53.            
  54.             if(column == (h-2)) //prints the sides of the square
  55.             {
  56.                 cout<<"*";
  57.             }
  58.         }
  59.         cout<<endl;
  60.     }
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. int main()
  69. {
  70.     char restart = 'y';
  71.     int choice;
  72.     int width;
  73.     int height;
  74.     int shift;
  75.    
  76.     cout << "Welcome to the Shape Creator program\n";
  77.     cout << "Would you like to make a square, rectangle or a shifted rectangle?\n"
  78.          << "Enter 1, 2, or 3: ";
  79.     cin >> choice;
  80.    
  81.     if (choice == 1)
  82.     {
  83.         do{
  84.             cout << "Please enter the width of your square: ";
  85.             cin >> width;
  86.             draw_square (width);
  87.             cout << "Would you like to restart the program? Y or N: ";
  88.             cin >> restart;
  89.         }while (restart == 'y' || restart == 'Y');
  90.     }
  91.  
  92.     else if (choice == 2)
  93.     {
  94.         do{
  95.             cout << "Please enter the width and height of your rectangle, separated by a space: ";
  96.             cin >> width, height;
  97.             draw_Square (width, height);
  98.             cout << "Would you like to restart the program? Y or N: ";
  99.             cin >> restart;
  100.         }while (restart == 'y' || restart == 'Y');
  101.     }
  102.    
  103.    
  104.    
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.    
  114.    
  115.     return 0;
  116.  
  117.  
  118.  
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement