help with a exercise of Accelerated C++
Hello,
I have this exercise :
The framing programm writes the mostly blank lines that seperates the borders from the greeting one character at the time. Change the programm so it writes all the spaces at one time.
So i thought this solution will work.
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
// ask for the person's name
cout << "Please enter your first name: ";
// read the name
string name;
cin >> name;
// build the message that we intend to write
const string greeting = "Hello, " + name + "!";
// the number of blanks surrounding the greeting
int pad ;
cout << "hoeveel spaties tussen de rand en de tekst :";
cin >> pad ;
const int pad2 = 2 ;
// the number of rows and columns to write
const int rows = pad2 * 2 + 3;
const string::size_type cols = greeting.size() + pad * 2 + 2;
// write a blank line to separate the output from the input
cout << endl;
// write `rows' rows of output
// invariant: we have written `r' rows so far
for (int r = 0; r != rows; ++r) {
string::size_type c = 0;
// invariant: we have written `c' characters so far in the current row
while (c != cols) {
// is it time to write the greeting?
if (r == pad2 + 1 && c == pad + 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
string z(pad," ");
cout << z ;
c=+pad ;
}
}
cout << endl;
}
return 0;
}
But I see now that z is not declared in this scope.
What is my thinking error ?
Roelof