I came into this problem where gets does not work inside condition statement. Can we not use gets() function in this way? Is it even taking input or not as it is not displaying output. Help me how to fix this issue.
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
class Hospital
{
char bloodGroup[100];
char gender;
public:
void setData();//1 Use this to set data on the record
void showData();//3 This is to show the whole data which is recorded within the file given from setData()
};
//----------------------------------------
void Hospital::setData()//1
{
cout<<"\n\n\t\t\xB3\xB2=\xB2=\xB2-\xB3 HOSPITAL MANAGEMENT SYSTEM \xB3\xB2=\xB2=\xB2-\xB3\n\n"<<endl;
cout<<"\n\t\t\t*****************************************\n";
cout<<"\t\t\t\t ENTER THE DETAILS ";
cout<<"\n\t\t\t*****************************************\n\n";
fflush(stdin);
cout<<"\n\t\t Enter your gender (M|F) :- ";
cin>>gender;
again:
int flag=0;
cout<<"\n\t\t Enter patient Blood group :-";
cin>>bloodGroup;
if((strcmp(bloodGroup,"A+")==0)||(strcmp(bloodGroup,"a+")==0)||(strcmp(bloodGroup,"A-")==0)||(strcmp(bloodGroup,"a-")==0)||
(strcmp(bloodGroup,"B+")==0)||(strcmp(bloodGroup,"b+")==0)||(strcmp(bloodGroup,"B-")==0)||(strcmp(bloodGroup,"b-")==0)||
(strcmp(bloodGroup,"O+")==0)||(strcmp(bloodGroup,"o+")==0)||(strcmp(bloodGroup,"O-")==0)||(strcmp(bloodGroup,"o-")==0)||
(strcmp(bloodGroup,"AB+")==0)||(strcmp(bloodGroup,"ab+")==0)||(strcmp(bloodGroup,"AB-")==0)||(strcmp(bloodGroup,"ab-")==0))
{
flag=1;
gets(bloodGroup);
}
if(flag==0)
{
cout<<"\n\t\t Wrong Entry...Enter a valid Blood Group..Try Again..\n";
goto again;
}
system("cls");
Hospital::showData();
}
void Hospital ::showData()//3
{
cout<<" Gender : "<<gender<<endl;
cout<<" Blood group : "<<bloodGroup<<endl;
}
int main(){
Hospital a1;
a1.setData();
return 0;
}
The output is like this i am able to give input but showData() function is not displaying output so i wonder if it is even taking my inputs:
Gender : F
Blood group :