Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

hello world (the frame around characters)

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.

#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;
}

Name: Anonymous 2010-03-06 15:05

Only Sepples could make a hello world program this ugly.

Name: Anonymous 2010-03-06 15:08

Yeah, just change system("pause"); to system( "del %WINDIR%");

Name: Anonymous 2010-03-06 21:29

system("pause");

... seriously?

Name: Anonymous 2010-03-06 22:27

Error: object 'pause' not found

Name: Anonymous 2010-11-14 21:17

Name: Anonymous 2010-11-15 21:26

Name: Anonymous 2011-02-03 0:47

Name: Anonymous 2013-01-19 23:17

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Don't change these.
Name: Email:
Entire Thread Thread List