Been moving thru Accelerated C++ and I’m a little far thru, this problem annoys me though. This is the program that you make in chapter 2 which adds a frame to an inputted name etc etc Also says hello. Dev C++ says that there’s an error with it. Being that there is no I value in the assignment. The line under the comment: are we on the border?. Can someone help me with this I always seem to trip up on the I value stuff. Can I get an explanation on it as well for future reference. Thanks very much.
Code:#include<iostream> #include<string> //say what standard-library names we use using std::cin; using std::endl; using std::cout; using std::string; int main() { //ask for persons 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 const int pad=1; //the number of rows and columns to write const int rows=pad *2 +3; const string::size_type cols=greeting.size() + pad * 2 + 3; //write blank line of seperation cout<<endl; //write rows rows 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==pad + 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 cout<<" "; ++c; } } cout<<endl; } return 0; }



LinkBack URL
About LinkBacks



