I'm new to both this forum and to programming. I'm having problem with this name framing-program. The asterisk after the 'greeting' doesn't align with the last column. Why? The solution is probably obvious, but please do help me :)
Here's the code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Please enter your name: ";
string name;
cin >> name;
const string greeting = "Hello, " + name + "!";
int pad = 2;
int rows = pad * 2 + 3;
string::size_type columns = greeting.size() + pad * 2 + 2;
cout << endl;
for (int r = 0; r != rows; ++r)
{
string::size_type c = 0;
while (c != columns)
{
if (r == 0 || r == rows - 1 || c == 0 || c == columns - 1)
{
cout << "*";
}
else if (r == pad + 1 && c == pad + 1)
{
cout << greeting;
c += greeting.size();
}
else
{
cout << " ";
}
++c;
}
cout << endl;
}
cin.get();
cout << "\n\n Press ENTER to continue...";
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );