Hey all, I'm not sure what problem 3 of Jumping into C++ is asking me to do. For those of you who do not have the book, I'll reprint it here.
"Modify the program you wrote for exercise 1 so that instead of always prompting the user for a last name, it does so only if the caller passes in a NULL pointer for the last name."
The first exercise it refers to has us use pointers (or references) to have a function that changes the value of two strings (calling by reference I believe?). My code for the fist problem is as follows:
Code:
#include <iostream>#include <string>
using namespace std;
void names(string *p_first, string *p_last)
{
cout << "What is your first name?:\n";
cin >> *p_first;
cout << "What is your last name?:\n";
cin >> *p_last;
}
int main()
{
string firstName, lastName;
names(&firstName, &lastName);
cout << firstName << " " << lastName;
return 0;
}
So yea, just don't know what the question is asking. Does it just want me to add an
Code:
if (p_last == NULL)
{
//asks for last name etc.
}
in the names() function? Seems a bit trivial but maybe I'm over-thinking this
thanks