I have made a program in C++ which does not accept the value of a an enumeration variable defined within a structure, when I pass the structure into a function.
It does not even accept the value YES or NO in the main function.
Help me out please. :)
It does not even accept the value YES or NO in the main function.
Help me out please. :)
Code:
#include <iostream>
using namespace std;
struct student
{
char name[20];
int age;
enum {YES,NO} admit;
union
{
int FSCMarks;
char ALMarks;
} marks;
int FSCcheck;
int ALcheck;
};
void computeEligibility(struct student);
void main()
{
int check,n;
cin>>n;
cin.ignore();
struct student *s=new struct student [n];
for (int i=0; i<n; i++)
{
cout<<"Enter name: ";
cin.getline(s[i].name,100,'\n');
cout<<"Enter age: ";
cin>>s[i].age;
cout<<"Enter 1 if FSc and 2 if A Level: ";
cin>>check;
if (check==1)
{
cout<<"Enter percentage in FSc: ";
cin>>s[i].marks.FSCMarks;
s[i].FSCcheck=1;
}
if (check==2)
{
cout<<"Enter grade in A Levels: ";
cin>>s[i].marks.ALMarks;
s[i].ALcheck=1;
}
computeEligibility(s[i]);
}
}
void computeEligibility(struct student s)
{
if (s.FSCcheck==1)
{
if(s.age<35 && s.marks.FSCMarks>85)
s.admit=YES;
else
s.admit=NO;
}
if (s.ALcheck==1)
{
if(s.age<35 && s.marks.ALMarks=='A')
s.admit=YES;
else
s.admit=NO;
}
if(s.admit==YES)
cout<<"Eligible.\n";
if(s.admit==NO)
cout<<"Not Eligible.\n";
}
Comment