Having a logical error.....Help please?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Yokil
    New Member
    • Nov 2011
    • 1

    Having a logical error.....Help please?

    Hey I'm doing this program for a project. It's running and everything. But I can't seem to get it to go further on. It terminates suddenly. Is something wrong with the logic?
    Here's the program


    Code:
    #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(n,m);
    	 choice=toupper(choice);
    	 if(choice=='Y')
    	 {
    	  ++n;
    	  dts.getlevel2_symptoms();
    	  m=dts.analyse_symptoms(n);
    	  choice=dts.display_message(n,m);
    	  choice=toupper(choice);
    	  if(choice=='Y')
    	  {
    		++n;
    		dts.getlevel3_symptoms();
    		m=dts.analyse_symptoms(n);
    		choice=dts.display_message(n,m);
    		choice=toupper(choice);
    		if(cho=='Y')
    		{
    		 ++n;
    		 dts.getlevel3_symptoms();
    		 m=dts.analyse_symptoms(n);
    		 cho=dts.display_message(n,m);
    		}
    	  }
    	 }
    	}
    
    
    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();
    	  int i=0;
    	  cout<< " *** MEDICAL DIAGONOSIS FORM *** "<<endl<<endl;
    	  for(i=0;i<9;i++)
    	  {
          cout<<"APPETITE (H(HIGH),/L(LOW),/N(NORMAL):" <<endl<<endl;
        
         cin>>s[i];
    	  
    	  ++i;
    	  
    	  cout<<"FREQUENCY OF THIRST(H(HIGH),/L(LOW)/N(NORMAL):"<<endl<<endl;
    	 
    	  cin>>s[i];
         
    	  ++i;
        
    	  cout<<"FREQUENCY OF URINATION(H(HIGH),/L(LOW),/N(NORMAL):";
        
         cin>>s[i];
    	  
    	  ++i;
        
    	  cout<<"VISION (I(IMPAIRMENT),/N(NORMAL)";
         
    	 
    	 cin>>s[i];
         
         ++i;
    
       cout<<"URINE SUGAR(P(PASSIVE)/A(ACTIVE);";
    	 
         cin>>s[i];
         
    	  ++i;
         
    	  cout<<"KETONUREA(P(PASSIVE)/A(ACTIVE)";
         
    	  cin>>s[i];
         
         ++i;
    	  
    	  cout<<"FASTING BLOOD SUGAR(H(HIGH)/L(LOW)/N(NOMAL)";
         
         cin>>s[i];
         
    	  ++i;
         
    	  cout<<"R B S (H(HIGH)/L(LOW)/N(NORMAL)";
         
    	  cin>>s[i];
    	  
         ++i;
         
    	  cout<<"FAMILY HISTORY OF DIABETES(P(PASSIVE)/A(ACTIVE)";
         
         cin>>s[i];
    	  
    	  ++i;
        
    	  cout<<"OGTT(D/N)";
         
    	  cin>>s[i];
         
    	  ++i;
    	  }
        }
    
    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]=='P' && s[7]=='H')
    			  result=-1;
    		       else
    			  {
    				 for(i=0;i&result;i++)
    				 {
    			      if(s[i]=='H'||s[i]=='P'||s[i]=='D'||s[i]=='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);
          }
    
    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 ;
    	       //	default : break;
    	       }
    	       return (ch);
    	     }
    
    
     
    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;
    		  return;
    	      }
     
    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;
    		 return;
    	}
    There are a few things missing without proper indentation also. The program is used to analyse whether a person has diabetes or not.

    Thank you guys <3
    Last edited by Banfa; Nov 23 '11, 04:37 PM. Reason: Added [code]...[/code] tags
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You have a lot of return statements in your program plus there are nested cases in your switch.

    Re-do your code. Try to have only one return. Do not nest cases, that just does not work. Add comments so others know what you intend.

    Learn to use your debugger.

    Comment

    Working...