Code:// Hello World! V 3_02_02 // Use of functions and variables // by SRS & the assistance of the // fine people at cprogramming.com #include <iostream> #include <string> using namespace std; string get_name() { string firstName; string lastName; string fullName; for(;;) { cout << "Please Enter Your First Name:" << endl; cin >> firstName; cout << "Please Enter Your Last Name:" << endl; cin >> lastName; fullName = firstName + " " + lastName; char yn; for(;;) { cout << "Please verify your correct name is " << fullName << endl; cout << "By entering \"Y\" or \"Yes\" if it is correct" << endl; cout << "or \"N\" or \"No\" if it is incorrect:" << endl; string verify; cin >> verify; int verifySize = verify.size(); if(verifySize <= 0) { cout << "Please enter \"Y\" or \"N\":" << endl; continue; } else { yn = verify[0]; break; } } if(tolower(yn) == 'y') { cout << "Hello World, from " << fullName << "!!"<< endl; break; // Exit the loop upon verification } else { cout << "Please try again:\n" << endl; continue; // Repeat the loop for any other answer } } return fullName; } int main() { string newUser = get_name(); // Get & Verify User's First & Last Name /* |Actions -----| |to ----------| |be ----------| |performed ---| |on ----------| |new ---------| |user --------| */ cout << newUser << ", this is the end of the road!" << endl; system ("PAUSE"); }
Ok many versions into this and that is what it looks like. Please feel free to suggest improvements, changes, possible errors, or any other comment you like before I move on to something else. Thanks to all of you who have helped me getting started with this.



LinkBack URL
About LinkBacks



