What is the error?

Here's the program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>

struct DATE
{
	int Date;
	int Month;
	int Year;
};

class STUDENT
{
  private:
	      
	      int Admno;
		  char Sname[20];
		  DATE DOB;

  public:
	      void Input()
		  {
			  cout<<"Enter Admission Number: ";
			  cin>>Admno;
			  cout<<"Enter Name of the Student: ";
			  gets(Sname);
			  cout<<"Enter Date of Birth of the student: ";
			  cout<<"Enter Date: ";
			  cin>>DOB.Date;
			  cout<<"Enter Month: ";
			  cin>>DOB.Month;
			  cout<<"Enter Year: ";
			  cin>>DOB.Year;
		  }

		  void Show()
		  {
			  cout<<"Admission Number: "<<Admno;
			  cout<<"Name: "<<Sname;
			  cout<<"Date of Birth: "<<endl;
			  cout<<"Date: ";
			  cin>>DOB.Date;
			  cout<<"Month: ";
			  cin>>DOB.Month;
			  cout<<"Year: ";
			  cin>>DOB.Year;

		  }

		   DATE RDOB()
		  {
			  return DOB;
		  }

};



void EnterStudents(STUDENT B[], int K)
{
	B[K].Input()	;
}

void DisplayStudents(STUDENT B[], int K)
{
	B[K].Show();
}

void DisplaySpecificStudents(STUDENT B[], int K)
{
 
		
	
	if(B[K].(RDOB().Date)==1 && B[K].(RDOB().Month)==1 && B[K].(RDOB().Year)==1990 || B[K].(RDOB().Date)==2 && B[K].(RDOB().Month)==2 && B[K].(RDOB().Year)==1990 || B[K].(RDOB().Date)==3 && B[K].(RDOB().Month)==3 && B[K].(RDOB().Year)==1990)
        B[K].Show();
	
}


void main()
{
	STUDENT B[50];
	int n;
	cout<<"Enter the number of student you'd be entering <=50 :";
	cin>>n;
	for(int i=0; i<n; i++)
	{
		EnterStudents(B,i);
	}

	for(i=0; i<n; i++)
	{
		DisplayStudents(B,i);
	}

	for(i=0; i<n; i++)
	{
		DisplaySpecificStudents(B,i);
	}

	getch();
}


The errors are:

Line 75: Member Identifier Expected
Line 76: If statement missing )
Line 78: Parameter B is never used.
Line 78: Parameter B is never used.


Why do these errors occur? And how to correct them?
Probably all stem from the missing parentheses.
closed account (z05DSL3A)
if(B[K].(RDOB().Date)==1 && B[K].... ==3 && B3 && B[K].(RDOB().Year)==1990)
Sorry to be blunt but What The F^&K is that about? I'm not surprised you have a problem.

Try breaking your conditions down into more manageable code.

I'm not sure what some of those parenthesis are about, I think you are trying to do something like:
1
2
3
4
5
    if(  (B[K].RDOB().Date == 1 && B[K].RDOB().Month == 1 && B[K].RDOB().Year == 1990 )
      || (B[K].RDOB().Date == 2 && B[K].RDOB().Month == 2 && B[K].RDOB().Year == 1990 )
      || (B[K].RDOB().Date == 3 && B[K].RDOB().Month == 3 && B[K].RDOB().Year == 1990 )
      )
        B[K].Show();

but that is still ugly code
Last edited on
That "if" statement on line 75 is pretty hard to parse with the human eye, but I don't think I can see a missing parenthesis.

It would be much easier to parse - and debug - that line if you organised it a bit more sensibly. For a start, why pass the entire array into the function along with an index? Why not just pass in a single STUDENT object?

Even keeping it with that signature:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void DisplaySpecificStudents(STUDENT B[], int K)
  STUDENT& stud = B[K];
  DATE studDOB =  stud.RDOB();
  if(studDOB.Date==1 && 
     studDOB.Month==1 && 
     studDOB.Year==1990 || 
     studDOB.Date==2 && 
     studDOB.Month==2 && 
     studDOB.Year==1990 || 
     studDOB.Date==3 && 
     studDOB.Month==3 && 
     studDOB.Year==1990)
        stud.Show();
	
}


then the whole thing becomes much more easy to look at and debug.

For starters, now that I've abstracted away a whole load of [] and (), I can see that the logic of the condition is very muddled. It looks as though you're checking whether the DOB is one of 01/01/1990, 02/02/1990 or 03/03/1990. If that's the case, you want some extra parentheses in there to ensure the expressions are evaluated in the correct order:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void DisplaySpecificStudents(STUDENT B[], int K)
  STUDENT& stud = B[K];
  DATE studDOB =  stud.RDOB();
  if((studDOB.Date==1 && 
      studDOB.Month==1 && 
      studDOB.Year==1990) || 
     (studDOB.Date==2 && 
      studDOB.Month==2 && 
      studDOB.Year==1990) || 
     (studDOB.Date==3 && 
      studDOB.Month==3 && 
      studDOB.Year==1990))
        stud.Show();
	
}


That's just a start... you could break it down even more, to make it more manageable.
Last edited on
- I would also place my bets on missing parenthesis.

- However, this code is badly formated in my opinion and as such, I'm not going to do through that incredibly long if statement.

- I would advise you to break that if statement up somehow, and perhaps by using one of the methods that have already been suggested.
Topic archived. No new replies allowed.