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;
Expert's answer

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 first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal