Answer to Question #8693 in C++ for Angela Kwee

Question #8693
getPatientPolicyNo( ): Returns the patient’s policy number.
If the patientPolicyNo is blank, then send a message to the screen and exit(2).
String getPatientPolicyNo( );

The compiler doesn't recognize the "" (space) I have in my control statement. It doesn't generate error. Can anyone help what I did wrong here? Thanks

String patientPolicyNo;

if (patientPolicyNo == "")
{
cerr << "Invalid policy number" << endl;
exit(2);
}

return patientPolicyNo;
1
Expert's answer
2012-04-24T11:10:24-0400

Try this:


#include <iostream>
#include <string>
using namespace std;

string patientPolicyNo;

string check(string str){
if ( str=="" ){
& cerr << "Invalid policy number" << endl;
& exit(2);
}
&
return str;

}

void main(){

printf("Enter the patient policy number: ");

getline(cin, patientPolicyNo);

cout<<check(patientPolicyNo);

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS