Hey guys. So I'm doing this project for my end-of-year exam and it's running. But I can't seem to go further beyond a point. This program asks the user as series of questions and then analyses the symptoms to give the result ie, if the user is diabetic or not. When i run the program, after the first question is answered, an error message comes up on the screen which says that the program has encountered a problem and has to terminate.
I think something's wrong with the main function. I am also very confused about the variables m and n in the program.
Here's the program, if any of you could point out the error in the logic of the program, it would really be great!
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void clrscr()
{
system("cls");
}
class diabetes
{
private:
char name[40];
float age;
int wt;
float ht;
char sex;
char *s;
public:
void welcome_screen(void);
void getvalue(void);
void getlevel1_symptoms(void);
void getlevel2_symptoms(void);
void getlevel3_symptoms(void);
int analyse_symptoms(int);
char display_message(int,int);
};
void main()
{
char ch,choice,cho;
//int m,n=2;
float m;
int n=1;
void diagnosis(void);
diabetes dts;
dts.welcome_screen();
dts.getvalue();
diagnosis();
dts.getlevel1_symptoms();
m=dts.analyse_symptoms(n);
choice=dts.display_message(m,n);
choice=toupper(choice);
if(choice=='Y')
{
++n;
dts.getlevel2_symptoms();
m=dts.analyse_symptoms(n);
choice=dts.display_message(m,n);
choice=toupper(choice);
if(choice=='Y')
{
++n;
dts.getlevel3_symptoms();
m=dts.analyse_symptoms(n);
choice=dts.display_message(m,n);
choice=toupper(choice);
if(cho=='Y')
{
++n;
dts.getlevel3_symptoms();
m=dts.analyse_symptoms(n);
cho=dts.display_message(m,n);
}
}
}
}
void diabetes::welcome_screen()
{
cout<<"********* W E L C O M E ********* "<<endl<<endl<<endl ;
cout<<"I N T E R N A T I O N A L I N D I A N S C H O O L "<<endl<<endl ;
cout<<" M E D I C A L D I A G N O S I S S O F T W A R E "<<endl<<endl;
cout<<"D O N E B Y : "<<endl<<endl;
cout<<"ANONYMOUS "<<endl<<endl;
cout<<"******** PRESS ANY KEY TO CONTINUE ********* "<<endl;
getch();
return;
}
void diabetes::getvalue()
{
clrscr();
cout<<" P E R S O N A L I N F O R M A T I O N"<<endl<<endl<<endl;
cout<<"N A M E :"<<endl<<endl;
gets(name);
cout<<"A G E :"<<endl<<endl;
cin>>age;
cout<<"W E I G H T :"<<endl<<endl;
cin>>wt;
cout<<"H E I G H T :"<<endl<<endl;
cin>>ht;
cout<<"S E X (M/F) :"<<endl<<endl;
cin>>sex;
getch();
return;
}
void diagnosis(void)
{
clrscr();
cout<<" ** D I A G N O S I S W I N D O W ** ";
cout<<"\n\n\n";
cout<<" Let's have a look at the symptoms.........";
cout<<"\n\n\n";
cout<<" Please enter the form in the next page .";
cout<<"\n\n\n\n\n\n\t\t\t ";
cout<<"***** PRESS ANY KEY ***** "<<endl<<endl;
getch();
}
void diabetes::getlevel1_symptoms(void)
{
clrscr();
cout<< " *** MEDICAL DIAGONOSIS FORM *** "<<endl<<endl;
for(int i=0;i<9;i++)
{
cout<<"FREQUENCY OF THIRST(H(HIGH),/L(LOW)/N(NORMAL):"<<endl<<endl;
cin>>s;
cout<<"FREQUENCY OF URINATION(H(HIGH),/L(LOW),/N(NORMAL):";
cin>>s;
cout<<"VISION (I(IMPAIRMENT),/N(NORMAL)";
cin>>s;
cout<<"URINE SUGAR(P(PASSIVE)/A(ACTIVE);";
cin>>s;
cout<<"KETONUREA(P(PASSIVE)/A(ACTIVE)";
cin>>s;
cout<<"FASTING BLOOD SUGAR(H(HIGH)/L(LOW)/N(NOMAL)";
cin>>s;
cout<<"R B S (H(HIGH)/L(LOW)/N(NORMAL)";
cin>>s;
cout<<"FAMILY HISTORY OF DIABETES(P(PASSIVE)/A(ACTIVE)";
cin>>s;
cout<<"OGTT(D/N)";
cin>>s;
}
}
int diabetes::analyse_symptoms(int n)
{
int i=0;
int count=0;
int result=0;
switch(n)
{
case 1: if(s[9]=='D' )
result=-1;
else
if(s[5]=='P'&& s[6]=='H' && s[7]=='H')
result=-1;
else
{
for(i=0;i&result;i++)
{
if(s=='H'||s=='P'||s=='D'||s=='I')
count++;
}
if(count>5)
result=-1;
}
break;
case 2: if((s[0]=='P')||(s[1]=='P')||(s[2]=='P')||(s[3]=='H')||(s[4]=='P')||(s[5]=='P')||(s[6]=='P'))
result=-1;
else
result=0;
break;
case 3: if((s[0]=='Y')&&(s[1]=='N')&&(s[2]=='W')&&(s[3]=='P')&&(s[4]=='P')||
(s[0]=='Y')&&(s[1]=='B')&&(s[2]=='W')&&(s[3]=='P')&&(s[4]=='P')||
(s[0]=='Y')&&(s[1]=='N')&&(s[2]=='M')&&(s[3]=='P')&&(s[4]=='P')||
(s[0]=='Y')&&(s[1]=='N')&&(s[2]=='Y')&&(s[3]=='P')&&(s[4]=='P'))
result=0;
else
result=-1;
break;
default:break;
}
return(result);
}
void diabetes::getlevel2_symptoms()
{
int j=0;
cout<<"PANCREATITIS(P/A) :";
cin>>s[j];
s[j]=toupper(s[j]);
j++;
cout<<"CARCINOMA(P/A) :";
cin>>s[j];
s[j]=toupper(s[j]);
++j;
cout<<"CIRHHOSIS(P/A) :";
cin>>s[j];
s[j]=toupper(s[j]);
++j;
cout<<" HCTS (H/L/N) :";
cin>>s[j];
s[j]=toupper(s[j]);
++j;
cout<<"HEPATITIS(P/A) :";
cin>>s[j];
s[j]=toupper(s[j]);
++j;
cout<<" HORMONAL DISORDER(P/A):";
cin>>s[j];
s[j]=toupper(s[j]);
++j;
cout<<" PANCREATECTOMY(P/A) :";
cin>>s[j];
s[j]=toupper(s[j]);
++j;
}
void diabetes::getlevel3_symptoms()
{
int k=0;
cout<<" AGE(young(Y)/Middle aged(M)/Elderly(E))";
cin>>s[k];
s[k]= toupper (s[k]);
++k;
cout<<"BODY WEIGHT(normal(N)/Above normal(A)/Below normal(B)/obese)";
cin>>s[k];
s[k]= toupper(s[k]);
++k;
cout<<" DURATION (weeks(W)/Months(M)/Years(Y))";
cin>>s[k];
s[k]= toupper(s[k]);
++k;
cout<<"KETONUREA(P/A)";
cin>>s[k];
s[k]= toupper(s[k]);
++k;
cout<<"AUTO ANTIBODIES(P/A)";
cin>>s[k];
s[k]= toupper(s[k]);
++k;
}
char diabetes::display_message(int n,int m)
{
char ch;
switch(n)
{
case 1:
switch(m);
{
case 0:
cout<<"THE PERSON IS NOT DIABETIC";
cout<<"PRESS ANY KEY TO QUIT." ;
cin>>ch;
break;
exit(0);
case -1:
cout<<"THE PERSON IS DIABETIC ";
cout<<"PROCEED (Y/N) ?";
cin>>ch;
break;
default: break;
}
break;
case 2:
switch(m)
{
case 0:
cout<<"IT IS PRIMARY DIABETES.";
cout<<"Proceed(Y/N)?";
cin>>ch;
break;
case -1:
cout<<"IT IS SECONDARY DIABETES";
cout<<"PRESS ANY KEY TO QUIT";
getch();
break;
}
break;
case 3:switch(m)
{
case 0:
cout<<" IT IS INSULIN DEPENDENT DIABETES";
cout<<"press any key to quit";
getch();
break;
case -1:
cout<<"IT IS NON INSULIN DEPENDENT DIABETES";
cout<<"PRESS ANY KEY TO QUIT .";
getch();
break;
default: break;
}
break ;
}
return (ch);
}