rectangle of asterisks

This is a discussion on rectangle of asterisks within the C++ Programming forums, part of the General Programming Boards category; i created a program where you input a height and width and the output is a rectangle of asterisks. and ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    1

    rectangle of asterisks

    i created a program where you input a height and width and the output is a rectangle of asterisks. and when a negative height or width or both is entered, the number changes to one, but the output screen is just black, can someone help me with this.


    Code:
     
    #include <iostream>
    using namespace std;
    int height;
    int width;
    int tmp;
    int tmp2;
    
    int main(){
          cout<<"Enter height rectangle: ";
    	  cin>>height;
             if(height < 1)
    			 height = 1;
    		 else
    			 if(height > 20)
    				 height = 20;
    		 
          cout<<"Enter width rectangle: ";
    	  cin>>width;
             if(width < 1)
    			 width = 1;
    		 else 
    			 if(width > 20)
    				 width = 20;
    
          for(tmp = 0; tmp != width; tmp++) 
    		  cout<<"*";
    
          for(tmp = 2; tmp != (height ); ++tmp){
    		  cout<<"\n*";
             for(tmp2 = 2; tmp2 != (width); ++tmp2) 
    			 cout<<" ";
    		 cout<<"*";
    	  }
          cout << "\n*";
          for(tmp = 1; tmp != (width); ++tmp)
          cout<<"*";                                 
          
          cout<<"\n";
    
    	  cout<<height<<endl;
    	  cout<<width<<endl;
    
    	  system("pause");
    	  return 0;
    }

  2. #2
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    Code:
             if(width < 1)
    			 width = 1;
    ..
    
     for(tmp = 1; tmp != (width); ++tmp)
    ^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. segmetation fault (reading and writing file in c)
    By tasosa in forum C Programming
    Replies: 5
    Last Post: 04-13-2009, 06:04 AM
  2. Struct Program to find Point in Rectangle
    By DMJKobam in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2009, 08:56 PM
  3. GUI structure in C
    By officedog in forum C Programming
    Replies: 36
    Last Post: 11-19-2008, 01:33 PM
  4. Point passed rectangle...
    By Hunter2 in forum Game Programming
    Replies: 15
    Last Post: 10-10-2003, 09:57 AM
  5. Collision detection algorithm
    By Hannwaas in forum Game Programming
    Replies: 5
    Last Post: 11-30-2001, 12:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21