I am just starting to learn C++ and having a wonderful time with it.
Here are my questions:
1: How could I use 1 function to do the work of getting and returning both names, the shortest way possible?
2: I can not find how to compare strings in the if (which is why it compares 1 & 2 rather than Y & N)
3: I would like to find out how to return to verify name if an invalid answer is given.
Thank you in advance for helping me learn C++Code:// Hello World! V 3_00_00 // Use of functions and variables // by SRS #include <iostream.h> #include <string> using namespace std; string firstName; string lastName; void first_name() { cout << "Please Enter Your First Name:" << endl; cin >> firstName; } void last_name() { cout << "Please Enter Your Last Name:" << endl; cin >> lastName; } // I am sure there is a way to use 1 function to return both names individually void main() { first_name(); last_name(); string fullName = firstName + " " + lastName; cout << "Please verify your correct name is " << fullName << endl; cout << "By entering '1' if it is correct" << endl; cout << "or '2' if it is incorrect:" << endl; // *Returning Point int verify; cin >> verify; if(verify == 1) // Can not figure out how to compare strings { cout << "Hello World, from " << firstName << " " << lastName << "!!"<< endl; cin.get(); } else if(verify == 2) // Can not figure out how to compare strings { cout << "Please try again:\n" << endl; main(); } else { cout << "I have no idea how to return to the verify from here" << endl; // Would like to know if it is possible to jump from here to *Returning Point cin.get(); } cin.get(); }![]()



LinkBack URL
About LinkBacks





