Int's are not the only data type that can be passed to a function. All valid data types, such as double, char, bool, string, etc. can be passed.
Ask the user to enter their first name and last name in main(). Pass those values to a function and produce the last two lines of output shown below:
Output:
Enter your first name: [user types: Mary Jo]
Enter your last name: [user types: De Arazoza]
Your full name is: Mary Jo De Arazoza
Your name can also be written as: De Arazoza, Mary Jo
#include <iostream>
#include <string>
using namespace std;
void function(string first, string last) {
string full = first + " " + last;
cout << "Your full name is: " << full << endl;
full = last + ", " + first;
cout << "Your name can also be written as: " << full << endl;
}
int main() {
string first, last;
cout << "Enter your first name: ";
getline(cin, first);
cout << "Enter yor last name: ";
getline(cin, last);
function(first, last);
return 0;
}
Comments
Leave a comment