Hi im new, Im getting crazy and playing with this values (2+3, 2+2) what are they!>?:
Code:
const string::size_type cols = greeting.size() + spacer * 2 + 2;
const int rows = pad * 2 + 3;
Code:
#include<iostream>#include<string>
using std::cout; using std::cin;
using std::endl; using std::string;
int main()
{
// Ask the name of the person.
cout << "Please enter your name: ";
// Read the name.
string name;
cin >> name;
// Build the greeting.
const string greeting = "Hello, " + name + "!";
// Set the ammount of spacing on the middle line between the stars and the greeting.
const int spacer = 10;
// Set the amount of space for the padding.
const int pad = 2;
// The amount of stars to be printed above and beneath the greeting (cols) and tbe amount of rows.
const string::size_type cols = greeting.size() + spacer * 2 + 2;
const int rows = pad * 2 + 3;
// Write a blank line to seperate input from output.
cout << endl;
// Write rows of output.
for(int r = 0; r != rows; ++r)
{
string::size_type c = 0;
while(c != cols)
{
// Is it time to write the greeting?
if(r == pad + 1 && c == spacer +1)
{
cout << greeting;
c += greeting.size();
}
else
{
// Are we on the border?
if(r == 0 || r == rows - 1 || c == 0 || c == cols - 1)
cout << "*";
else
cout << " ";
++c;
}
}
cout << endl;
}
return 0;
}
Thanks