GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-May-2005, 16:24
nika1p2 nika1p2 is offline
New Member
 
Join Date: May 2005
Posts: 1
nika1p2 is on a distinguished road

Help with interactive program, please


I started to write this program but can't even get through the 1st part of it. Please, help.

Objective: White an interactive program which makes a preliminary diagnosis of influenza, cold, allerty, or unknown.

The output must look like the following:

Clark Hospital Diagnostic Center (Note 1)

Enter the patient number (0 to exit): 452382
Invalid patient number (Note 2)
Enter the patient number (0 to exit): 453282

Which of the following symptoms does the patient have (Y for yes, N for no);

Fever -------- y (Note 3)
Headache ----- N
Sore Throat -- m
Invalid entry.
Sore Throat -- Yes
Cough -------- y
Sniffles ----- n
Sneezes ------ n

The preliminary diagnosis is: Influenza (Note 4)

Enter the patient number (0 to exit): 0 (Note 5)

Diagnostic Program Terminated

Notes

1.

Display this heading line only once i.e. when the program is first started up.
2.

If the patient number fails to pass the mod 10 check digit technique, display "Invalid patient number." and prompt the user to enter a correct patient number. The mod 10 check digit technique is discussed below.
3.

Allow for either an upper or lower case response. If the response is neither Y, y, N nor n, display "Invalid entry." and reprompt the user. Use either getc(stdin) or its variant getchar(c) for reading the user response. Finally, your program should have no difficulty dealing with responses such as Yes, NO, YUP, NOPE etc. as-long-as the first character can be construed as a yes or no response.
4.

It is entirely possible the patient might have more the one diagnosis, be sure to display all possibilities.

5.

If a patient number of 0 (zero) is entered, terminate the program else continue to prompt for symptoms.

Technique: mod 10 Check Digit

To generate a check digit using the mod 10 technique, work from right to left. First multiply the digits in the odd positions by 2. if an individual result is greater than 10, add 1 to the units position to obtain a single digit adjusted result. Sum the results along with the even-positioned digits. The number that must be added to make this result evenly divisible by 10 is the check digit. (page 423)

Example: Consider a patient number 835174. The least significant digit (4) is the check digit. To determine if the (actual) patient number (83517) is a valid patient number do the following:

1.

Extract the odd numbered digits from right to left from the actual patient number. These would be 7, 5 and 8.
2.

Multiply each by 2:

7 · 2 = 14

5 · 2 = 10

8 · 2 = 16

3.

If any of the products from step 2 are greater than 10, add 1 to the units position and discard the remainder of the product e.g. since 7 · 2 = 14 add 1 to 4 (the units position) and discard everything else.
4.

Sum the adjusted products plus the digits from the even numbered positions:

5 + (1) + 10 + (3) + 7 = 26

(the digits in parenthesis are the even numbered digits).
5.

Find the largest number greater than or equal to the above sum evenly divisible by 10 - 30 for this example.
6.

Find the difference between the next largest number (30) and the sum (26) i.e. 30 - 26 = 4. Four is the check digit.

Any digit other than 4, would invalidate the patient number 83517[.]

This is what I have so far (for the mod 10 check digit):

CPP / C++ / C Code:
#include <stdio.h>
main()
{
  int pn, cd, d1, d2, d3, d4, d5, new_d1, new_d3, new_d5;
  int total, new_total, cd_new;

  do {
  fputs ("\nClark Hospital Diagnostic Center\n\n", stdout);
  printf ("Enter the patient number (0 to exit): ");
  scanf ("%i", &pn);

  cd = pn % 10;
  pn /= 10;

  d1 = (pn % 10) * 2;
  pn /= 10;

  d2 = pn % 10;
  pn /= 10;

  d3 = (pn % 10) * 2;
  pn /= 10;

  d4 = (pn % 10);
  pn /= 10;

  d5 = (pn % 10) * 2;

  if (d1 > 10)
    new_d1 = (d1 % 10) + 1;
  else
    new_d1 = d1;

  if (d3 > 10)
    new_d3 = (d3 % 10) + 1;
  else
    new_d3 = d3;

  if (d5 > 10)
    new_d5 = (d5 % 10) + 1;
  else
    new_d5 = d5;

  total = new_d1 + d2 + new_d3 + d4 + new_d5;

  while (total % 10 != 0)
    new_total = total + 1;

  cd_new = new_total - total;

  if (cd_new != cd)
    fputs ("  Invalid patient number\n", stdout);
  }
  while (pn > 0);

  printf ("%i, %i", cd, cd_new);
  return 0;
}


My problem at this point is that after I enter the patient number and press return key, nothing happens. The pointer gets me to the new line and just sits there. I cannot figure out where did I go wrong in my source code. Please, somebody help. thank you.
Last edited by LuciWiz : 08-May-2005 at 23:13. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 09-May-2005, 00:22
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
First, read the Guidelines.....

Second, why are you using fputs(..., stdout) then printf()? Use one or the other...

Try putting printf() statements in key spots (after your input, after calculations, etc.) to see what your program is doing.

You will then find that
CPP / C++ / C Code:
  while (total % 10 != 0)
    new_total = total + 1;
is your problem. It's an infinte loop. total%10 will never equal zero since total is never changed.
__________________

Age is unimportant -- except in cheese
 
 

Recent GIDBlogMeeting the populace by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
[TUTORIAL] Calling an external program in C (Linux) dsmith C Programming Language 4 22-Apr-2005 13:30
fltk-2.0 cvs Plumb FLTK Forum 20 13-Nov-2004 07:10
Need help with a C program (Long) McFury C Programming Language 3 29-Apr-2004 20:06

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:32.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.