473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

1
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


Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<ctype.h>
  5. #include<process.h>
  6.  
  7. void clrscr()
  8. {
  9.     system("cls");
  10. }
  11.  
  12.  
  13.  
  14. class diabetes
  15.      {
  16.          private:
  17.              char name[40];
  18.              float age;
  19.              int wt;
  20.              float ht;
  21.              char sex;
  22.              char *s;
  23.          public:
  24.           void welcome_screen(void);
  25.           void getvalue(void);
  26.           void getlevel1_symptoms(void);
  27.           void getlevel2_symptoms(void);
  28.           void getlevel3_symptoms(void);
  29.           int analyse_symptoms(int);
  30.           char display_message(int,int);
  31.      };
  32. void main()
  33.     {
  34.      char ch,choice,cho;
  35.      //int m,n=2;
  36.      float m;
  37.      int n=1;
  38.      void diagnosis(void);
  39.      diabetes dts;
  40.      dts.welcome_screen();
  41.      dts.getvalue();
  42.      diagnosis();
  43.      dts.getlevel1_symptoms();
  44.      m=dts.analyse_symptoms(n);
  45.      choice=dts.display_message(n,m);
  46.      choice=toupper(choice);
  47.      if(choice=='Y')
  48.      {
  49.       ++n;
  50.       dts.getlevel2_symptoms();
  51.       m=dts.analyse_symptoms(n);
  52.       choice=dts.display_message(n,m);
  53.       choice=toupper(choice);
  54.       if(choice=='Y')
  55.       {
  56.         ++n;
  57.         dts.getlevel3_symptoms();
  58.         m=dts.analyse_symptoms(n);
  59.         choice=dts.display_message(n,m);
  60.         choice=toupper(choice);
  61.         if(cho=='Y')
  62.         {
  63.          ++n;
  64.          dts.getlevel3_symptoms();
  65.          m=dts.analyse_symptoms(n);
  66.          cho=dts.display_message(n,m);
  67.         }
  68.       }
  69.      }
  70.     }
  71.  
  72.  
  73. void diabetes::welcome_screen()
  74.      {
  75.      cout<<"********* W E L C O M E ********* "<<endl<<endl<<endl ;
  76.      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  ;
  77.      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;
  78.      cout<<"D O N E  B Y  : "<<endl<<endl;
  79.      cout<<"ANONYMOUS"<<endl<<endl;
  80.      cout<<"******** PRESS ANY KEY TO CONTINUE ********* "<<endl;
  81.      getch();
  82.         return;
  83.     }
  84.  
  85.  
  86.     void diabetes::getvalue()
  87.     {
  88.      clrscr();
  89.      cout<<" P E R S O N A L   I N F O R M A T I O N"<<endl<<endl<<endl;
  90.      cout<<"N A M E        :"<<endl<<endl;
  91.      gets(name);
  92.      cout<<"A G E          :"<<endl<<endl;
  93.      cin>>age;
  94.      cout<<"W E I G H T    :"<<endl<<endl;
  95.      cin>>wt;
  96.      cout<<"H E I G H T    :"<<endl<<endl;
  97.      cin>>ht;
  98.      cout<<"S E X (M/F)    :"<<endl<<endl;
  99.      cin>>sex;
  100.      getch();
  101.        return;
  102.     }
  103.  
  104.  
  105. void diagnosis(void)
  106.      {
  107.       clrscr();
  108.       cout<<" **  D I A G N O S I S   W I N D O W **   ";
  109.       cout<<"\n\n\n";
  110.       cout<<" Let's have a look at the symptoms.........";
  111.       cout<<"\n\n\n";
  112.       cout<<" Please enter the form in the next page .";
  113.       cout<<"\n\n\n\n\n\n\t\t\t ";
  114.       cout<<"***** PRESS ANY KEY ***** "<<endl<<endl;
  115.       getch();
  116.      }
  117.  
  118. void diabetes::getlevel1_symptoms(void)
  119.     {
  120.       clrscr();
  121.       int i=0;
  122.       cout<< " *** MEDICAL DIAGONOSIS FORM *** "<<endl<<endl;
  123.       for(i=0;i<9;i++)
  124.       {
  125.       cout<<"APPETITE (H(HIGH),/L(LOW),/N(NORMAL):" <<endl<<endl;
  126.  
  127.      cin>>s[i];
  128.  
  129.       ++i;
  130.  
  131.       cout<<"FREQUENCY OF THIRST(H(HIGH),/L(LOW)/N(NORMAL):"<<endl<<endl;
  132.  
  133.       cin>>s[i];
  134.  
  135.       ++i;
  136.  
  137.       cout<<"FREQUENCY OF URINATION(H(HIGH),/L(LOW),/N(NORMAL):";
  138.  
  139.      cin>>s[i];
  140.  
  141.       ++i;
  142.  
  143.       cout<<"VISION (I(IMPAIRMENT),/N(NORMAL)";
  144.  
  145.  
  146.      cin>>s[i];
  147.  
  148.      ++i;
  149.  
  150.    cout<<"URINE SUGAR(P(PASSIVE)/A(ACTIVE);";
  151.  
  152.      cin>>s[i];
  153.  
  154.       ++i;
  155.  
  156.       cout<<"KETONUREA(P(PASSIVE)/A(ACTIVE)";
  157.  
  158.       cin>>s[i];
  159.  
  160.      ++i;
  161.  
  162.       cout<<"FASTING BLOOD SUGAR(H(HIGH)/L(LOW)/N(NOMAL)";
  163.  
  164.      cin>>s[i];
  165.  
  166.       ++i;
  167.  
  168.       cout<<"R B S (H(HIGH)/L(LOW)/N(NORMAL)";
  169.  
  170.       cin>>s[i];
  171.  
  172.      ++i;
  173.  
  174.       cout<<"FAMILY HISTORY OF DIABETES(P(PASSIVE)/A(ACTIVE)";
  175.  
  176.      cin>>s[i];
  177.  
  178.       ++i;
  179.  
  180.       cout<<"OGTT(D/N)";
  181.  
  182.       cin>>s[i];
  183.  
  184.       ++i;
  185.       }
  186.     }
  187.  
  188. int diabetes::analyse_symptoms(int n)
  189.  
  190.     {
  191.         int i=0;
  192.         int count=0;
  193.       int result=0;
  194.       switch(n)
  195.     {
  196.      case 1:    if(s[9]=='D' )
  197.             result=-1;
  198.             else
  199.                  if(s[5]=='P'&& s[6]=='P' && s[7]=='H')
  200.               result=-1;
  201.                else
  202.               {
  203.                  for(i=0;i&result;i++)
  204.                  {
  205.                   if(s[i]=='H'||s[i]=='P'||s[i]=='D'||s[i]=='I')
  206.                 count++;
  207.                  }
  208.                  if(count>5)
  209.                 result=-1;
  210.               }
  211.                break;
  212.  
  213.      case 2: if((s[0]=='P')||(s[1]=='P')||(s[2]=='P')||(s[3]=='H')||(s[4]=='P')||(s[5]=='P')||(s[6]=='P'))
  214.              result=-1;
  215.          else
  216.              result=0;
  217.              break;
  218.      case 3: if((s[0]=='Y')&&(s[1]=='N')&&(s[2]=='W')&&(s[3]=='P')&&(s[4]=='P')||
  219.  
  220.      (s[0]=='Y')&&(s[1]=='B')&&(s[2]=='W')&&(s[3]=='P')&&(s[4]=='P')||
  221.  
  222.      (s[0]=='Y')&&(s[1]=='N')&&(s[2]=='M')&&(s[3]=='P')&&(s[4]=='P')||
  223.  
  224.      (s[0]=='Y')&&(s[1]=='N')&&(s[2]=='Y')&&(s[3]=='P')&&(s[4]=='P'))
  225.           result=0;
  226.         else
  227.             result=-1;
  228.          break;
  229.      default:break;
  230.     }
  231.        return(result);
  232.       }
  233.  
  234. char diabetes::display_message(int n,int m)
  235.  
  236.       {
  237.        char ch;
  238.  
  239.          switch(n)
  240.      {
  241.       case 1:
  242.           switch(m);
  243.               {
  244.                case 0: 
  245.                      cout<<"THE PERSON IS NOT DIABETIC";
  246.  
  247.                      cout<<"PRESS ANY KEY TO QUIT." ;
  248.  
  249.                    cin>>ch;
  250.                    break;
  251.                      exit(0);
  252.  
  253.                  case -1:
  254.  
  255.  
  256.                      cout<<"THE PERSON IS DIABETIC ";
  257.  
  258.                      cout<<"PROCEED (Y/N)  ?";
  259.  
  260.                    cin>>ch;
  261.                    break;
  262.  
  263.                default: break;
  264.               }
  265.           break;
  266.  
  267.  
  268.  
  269.  
  270.         case 2:
  271.             switch(m)
  272.             {
  273.                case 0: 
  274.                     cout<<"IT IS PRIMARY DIABETES.";
  275.  
  276.                     cout<<"Proceed(Y/N)?";
  277.  
  278.                    cin>>ch;
  279.                    break;
  280.  
  281.                 case -1: 
  282.                     cout<<"IT IS SECONDARY DIABETES";
  283.  
  284.                     cout<<"PRESS ANY KEY TO QUIT";
  285.                    getch();
  286.                    break;
  287.  
  288.                    }
  289.             break;
  290.  
  291.         case 3:switch(m)
  292.          {
  293.                 case 0: 
  294.                 cout<<" IT IS INSULIN DEPENDENT DIABETES";
  295.  
  296.                 cout<<"press any key to quit";
  297.                 getch();
  298.                 break;
  299.  
  300.  
  301.                case -1: 
  302.                      cout<<"IT IS NON INSULIN DEPENDENT DIABETES";
  303.  
  304.  
  305.  
  306.                      cout<<"PRESS ANY  KEY TO QUIT .";
  307.                      getch();
  308.                    break;
  309.  
  310.               //       default: break;
  311.  
  312.          }
  313.  
  314.           // break ;
  315.            //    default : break;
  316.            }
  317.            return (ch);
  318.          }
  319.  
  320.  
  321.  
  322. void diabetes::getlevel2_symptoms()
  323.            {
  324.  
  325.         int j=0;
  326.  
  327.           cout<<"PANCREATITIS(P/A)  :";
  328.  
  329.           cin>>s[j];
  330.           s[j]=toupper(s[j]);
  331.           j++;
  332.  
  333.           cout<<"CARCINOMA(P/A)  :";
  334.  
  335.           cin>>s[j];
  336.           s[j]=toupper(s[j]);
  337.           ++j;
  338.  
  339.           cout<<"CIRHHOSIS(P/A)     :";
  340.  
  341.           cin>>s[j];
  342.           s[j]=toupper(s[j]);
  343.           ++j;
  344.  
  345.           cout<<" HCTS  (H/L/N)     :";
  346.  
  347.           cin>>s[j];
  348.           s[j]=toupper(s[j]);
  349.           ++j;
  350.  
  351.           cout<<"HEPATITIS(P/A)    :";
  352.  
  353.           cin>>s[j];
  354.           s[j]=toupper(s[j]);
  355.           ++j;
  356.  
  357.           cout<<" HORMONAL DISORDER(P/A):";
  358.  
  359.  
  360.           cin>>s[j];
  361.           s[j]=toupper(s[j]);
  362.           ++j;
  363.  
  364.           cout<<" PANCREATECTOMY(P/A) :";
  365.  
  366.           cin>>s[j];
  367.           s[j]=toupper(s[j]);
  368.           ++j;
  369.           return;
  370.           }
  371.  
  372. void diabetes::getlevel3_symptoms()
  373.           {
  374.          int k=0;
  375.  
  376.  
  377.          cout<<" AGE(young(Y)/Middle aged(M)/Elderly(E))";
  378.  
  379.          cin>>s[k];
  380.          s[k]= toupper (s[k]);
  381.          ++k;
  382.  
  383.          cout<<"BODY WEIGHT(normal(N)/Above normal(A)/Below normal(B)/obese)";
  384.  
  385.          cin>>s[k];
  386.          s[k]= toupper(s[k]);
  387.          ++k;
  388.  
  389.          cout<<" DURATION (weeks(W)/Months(M)/Years(Y))";
  390.  
  391.          cin>>s[k];
  392.          s[k]= toupper(s[k]);
  393.          ++k;
  394.  
  395.  
  396.          cout<<"KETONUREA(P/A)";
  397.  
  398.          cin>>s[k];
  399.          s[k]= toupper(s[k]);
  400.          ++k;
  401.  
  402.          cout<<"AUTO ANTIBODIES(P/A)";
  403.  
  404.          cin>>s[k];
  405.          s[k]= toupper(s[k]);
  406.          ++k;
  407.          return;
  408.     }
  409.  
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
Nov 23 '11 #1
1 1577
weaknessforcats
9,208 Expert Mod 8TB
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.
Nov 23 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Stefan van Roosmalen | last post by:
Hi there, I am using some example PHP code to build a counter for a page on my webserver. When going to that page, I will see the following error message: Warning: mysql_fetch_row(): supplied...
9
by: John Pether (john | last post by:
have been working with a site and today started getting an error when uploaded page on the live server...everything works well locally... The XML page cannot be displayed Cannot view XML input...
2
by: Victor M | last post by:
Hello everyone. I'm running Oracle 8.0 on NT4 (yep thats right) and running SQL*Plus 8.03. I'm typing the following at the SQL*Plus prompt: 1. Create Table EMPLOYEES 2. ( 3. ...
2
by: Ryan | last post by:
I get an error every so often with a DTS package on SQL 7. Error as follows. The connection is currently being used by a task. The connection cannot be closed or re-used. This doesn't happen...
0
by: agb | last post by:
Hi I am a new VS.NET user I have installed it yet But I have a problem while creating a new project the error is " VC package is not installed or not registered " could you help me please...
1
by: Steven | last post by:
Hi. I have the following sql statement: SELECT AVG(grade) FROM tblEvalGrades WHERE SSN='123456789' I get the following error when trying to output my table in my datagrid: ERROR: Decimal byte...
12
by: DannyB | last post by:
I'm just learning Python. I've created a simple coin flipper program - here is the code: #Coin flipper import random heads = 0 tails = 0 counter = 0
2
by: zenfor | last post by:
Hi, appreciate any help with this, I can't seem to get past this error. The Price field is a Number Data Type. This is part of some code that is adding records to a database. The 3 lines of...
1
by: slippingslider | last post by:
can someone pls tell me why this thing would not calculate my division intergers and show it within my struct. PLS HELP I'M NEW TO C++, AND HAVE SPENT 4 DAYS TRYING TO FIND OUT WHY I CANT DO THIS...
1
by: Matt | last post by:
I'm using classic ASP with an Access 2003 database, running on Win 2003 Server (IIS 6), trying to update a table and get the following error: Syntax error in UPDATE statement. -...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.