Name: Anonymous 2010-03-06 15:02
Hey guys i know i havent been on in a while. I havent been on lately because of school and other stuff..........
well anyways i am working with c++ by reading through the book Accelerated C++ by Andrew Koeing and Barbara E. Moo and i came across a problem that they get you to work out at the end of the chapter. The question/challenge was to change the frame around a hello world program. Like to change the spaces between each side and the top and bottom.
well anyways i am working with c++ by reading through the book Accelerated C++ by Andrew Koeing and Barbara E. Moo and i came across a problem that they get you to work out at the end of the chapter. The question/challenge was to change the frame around a hello world program. Like to change the spaces between each side and the top and bottom.
#include <iostream>
#include <string>
using namespace std;
int main() {
cout<<"what is your name: \n";
string name;
cin>>name;
string greeting = "hello " +name+ " !";
int top_pad=1; //1 space from the greeting to the top part of the frame
int side_pad=2;// space from one side to the beggining of the greeting to the end of the greeting to the other side
const int rows= top_pad *2 + 3;
const int cols = greeting.size() + ( side_pad *2 +2); //how many colums there are in the frame
cout<< endl;
for(int r = 0; r != rows; r++) {
string::size_type c = 0;
while( c != cols) {
//to see were you are at to print the greeting
if(r== top_pad + 1 && c==side_pad +1) {
cout<< greeting;
c += greeting.size();
}else{
if( r == 0 || r== rows -1 || //to know if you are on the far left or far right colum to print an asterisk to the frame
c == 0 || c== cols -1) {
cout<< "*";
}else{
cout<<" "; //you arent righting the greeting and you arent at the end of the colum so put a space
c++;
}
}
}
}
system("pause");
return 0;
}