Okay I have fined like 99% of my code but I am getting some kind of return error.
error C4716: 'personType::isFirstEqual' : must return a value
I can't seem to figure it out if you all could help me that would be great!
This function declaration says that isFirstEqual returns a string type. However,
1 2 3 4 5 6 7 8
string personType::isFirstEqual(string &newFirst)
{
cout << "Enter a first name to compare" << endl;
cin >> newFirst;
if (firstName.compare(newFirst) != 0)
std::cout << firstName << " is not " << newFirst << '\n';
else cout << firstName << " is the same as " << newFirst << endl;
}
This only outputs and does not return anything. I would either make isFirstEqual return void or change the header to
bool personType::isFirstEqual(string &newFirst);
and return true or false depending on if it's equal. Hopefully that helped.
I hope you don't mind me asking, what is the difference between outputs and return. For some reason they are the same thing to me.
I changed it the code to the to what you recommended bool personType::isFirstEqual(string &newFirst);
and I also changed it to the .cpp file
1 2 3 4 5 6 7 8 9 10
bool personType::isFirstEqual(string &newFirst)
{
cout << "Enter a first name to compare" << endl;
cin >> newFirst;
if (firstName.compare(newFirst) != 0)
std::cout << firstName << " is not " << newFirst << endl;
else
cout << firstName << " is the same as " << newFirst << endl;
}
Am i going about this all wrong? Because I feel like I am. Forgive me if I am making no sense, I am tired and I am not entirely thinking straight.
Oh wait, so I just added something and it seems to work fine, but another problem has arrived.
1 2 3 4 5 6 7 8 9 10 11
bool personType::isFirstEqual(string &newFirst)
{
cout << "Enter a first name to compare" << endl;
cin >> newFirst;
if (firstName.compare(newFirst) != 0)
std::cout << firstName << " is not " << newFirst << endl;
else
cout << firstName << " is the same as " << newFirst << endl;
return 0;
}
So the program works fine, except now it says " Enter a firs name to compare" twice.
Is that because of return 0; ?
Of course, no problem.
A return statement sends data back to the calling function.
So in this case, if main() were to call your isFirstEqual() function, it expects to receive a boolean value back.
Output is completely different. Output simply sends data to the screen, file, or something else. A file can output one thing and return another. However, it can only and MUST return what it's function declariation specifies.
The problem with your function, both before and now, is that you are outputting but not returning anything. When I said return true and false I mean something along the lines of the following function:
1 2 3 4
bool isGreater(int a, int b) {
if (a > b) returntrueelsereturnfalse
}
if you don't want to return anything, then set the function type to void:
Okay, that makes sense regarding the output and the return.
Ahh, I think that is what I wanted. I don't think I wanted to return anything, I just wanted to output.
Thanks!.
If you don't mind me bothering you some more, it keeps on out putting "Enter a first Name" twice and I have to input twice, however when it comes to the last name one it out puts it twice but I only enter once.