problem with my code

This is a discussion on problem with my code within the C++ Programming forums, part of the General Programming Boards category; i'm having a few problems with the code i've written. Th code presents a user with a menu, the user ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    10

    problem with my code

    i'm having a few problems with the code i've written. Th code presents a user with a menu, the user to enter a patient must select 'a' to allocate a patient and enter details. I'm currently working with the good ward only so the user must press 'g' when asked for ward condition. The details are saved in the appropriate array structure. The problem with my code is that when i select the view ward status option and then good ward 'g' to view the details entered, the data doesnt display from the array...can anyone help me on this please? thanks in advance
    Last edited by stilllearning; 04-08-2003 at 02:42 PM.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    void Patient::Allocate_Bed (void){
    int i,j,k;
    --------------------
    int main (void){

    Ward Hospital[13];
    Patient Details[13];
    char Option;
    int i, j;


    You never intialize i, j, k in Allocate_Bed(), nor i, j in main(), and since you never assign them a value, they contain junk values. (You should always initialize variables with 0 until you assign them a value.) So, in these lines:
    Code:
    case 's': Hospital[j].Bed_Status();
    	 		  break;
    		case 'a': Details[i].Allocate_Bed();
    	  		  break;
    		case 'd': Details[i].Discharge();
    	  		  break;
    Hospital[j] has an index that is some random junk value, and it certainly does not correspond to Details[i] whose index is another random junk value, and both will most likely be out of bounds; the indexes for Hospital and Details must be between 0 and 12. The compiler allows you to use indexes that are out of bounds, so you won't get a compiler error, but at runtime bad things happen, and the program will fail.
    Code:
    switch(Key){
    	case 'g':Good_Condition();
    		 break;
    There is no global function Good_Condition(). It's a class function and must be called on a class object, e.g.

    a_Ward.Good_Condition();
    Last edited by 7stud; 04-08-2003 at 02:36 PM.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    10
    Thank u!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! it works now your the best!

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Thank u!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    it works now your the best!
    Hmmm...you should read the last reply I got.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 11:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 06:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 02:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-06-2003, 12:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21