c++ - CPP- Square Hollow- What is the mistake? -


can please me? worte code compiles fine @ first round when loops doesnt print out properly. cant find mistake.. thank you! when compile xcode first gave right square hollow when input second time did not print out square.

#include <iostream> using std::cout; using std::cin; using std::endl;   #include <string> using std::string; #include <cstdlib>  int main() {     int a;     int b;     int num=0;     string buf;      //initialize , b     = 1;     b = 1;      // ask user repeat process again @ end of first promt     while( true )     {         cout << "please enter size of square between #1-20: \n";         cin >> buf; num = atoi (buf.c_str());         cin.ignore(1000, 10);          if( num < 1 || num > 20 )             break;          //process of printing square         while ( num >= a)         {             b = 1;             while ( num >= b )             {                 if ( == 1 || == num || b == 1 || b == num )                     cout << "*";                 else                     cout << " ";                 b++;             }             cout << endl;             a++;         }     } } 

you not resetting , b variables, need put these lines

//initialize , b = 1; b = 1; 

at beginning inside of while(true) loop


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -