This code hangs on me running. The problem is that "r" does not count right (not like it is directed under FOR expression). Does the problem lay beyond the code?
#include <iostream>
#include<string>
using namespace std;
// using std::cin;
// using std::endl;
// using std::cout;
// using std::string;
int main()
{
cout << "Please enter your name: ";
string name;
cin >> name;
const string greeting = name;
const int pad = 1;
const int rows = pad*2 + 3;
const string::size_type cols = greeting.size() + pad*2 + 2;
cout << endl;
// int r = 0;
// while( r != rows )
for ( int r = 0; r != rows; ++r )
{
string::size_type c = 0;
while (c != cols )
{
// cout << "\nr= " << r << "\n";
// cout << "c= " << c << "\n";
// system("pause");
if ( r == pad + 1 && c == pad + 1 )
{
cout << greeting;
c += greeting.size();
}else
{
if ( r = 0 || r == rows-1 || c == 0 || c == cols-1 )
cout << "*";
else
cout << " ";
++c;
}
}
cout << endl;
// r=r+1;
}
system( "pause>null" );
return 0;
}