vendredi 2 novembre 2018

No match for 'operator' == when programming in C++

I am trying to create a program in C++ that writes to a register. But in the implementation of the class I created I get the following error when trying to run the code : No match for 'operator==' when trying to set the study level of the student. The following is the whole code. I hope you understand what I am trying to do . Thank you in advance!

#include "student.h"
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

// constructor 1
student::student()
{
studentName = " ";
studentAge = 0;
studentGender = ' ';
studentLevel= " ";
}
// constructor 2 parameterised constructor
student::student( string name, int age, char gender,string level )
{
studentName = name;
studentAge = age;
studentGender = gender;
studentLevel=level;
}
// public function setName
void student::setName( string s )
{
studentName = s;
return;
}
// public function setAge
void student::setAge( int age )
{
if( age > 0 && age < 120 )
{
    studentAge = age;
} else
{
    cout << age << " is out of allowed range ( 1 to 119 ) so not entered in 
record " << endl;
}
return;
}
// public function setGender
void student::setGender( char gender)
{
if( gender == 'F' || gender == 'M' )
{
    studentGender = gender;
} else
{
    cout << gender << " is not allowed: should be M or F.  Not entered in 
record " << endl;
}
return;
}


//public function setLevel
void student::setLevel ( string level)
{
if (level == 'UG1' ||  level == 'UG2' || level== 'UG3' || level == 'UG4')
   {

    studentLevel=level;
}
else
{
    cout<<level<< "is not allowed: Should be one of the ones shown. Not 
entered in register"
}
return;
}
//public function writeRecord
void student::writeRecord()
{
cout << "Student Name   Age   Gender    Level" << endl;
cout << setw(12) << studentName << setw(6) << studentAge << setw(9) << 
studentGender <<studentLevel<<setw(9)<< endl;
return;
}

// public function getName
string student::getName()
{
return studentName;
}
/public function getAge
int student::getAge()
{
return studentAge;
}
//public function getGender
char student::getGender()
{
return studentGender;
}
string student::getLevel()
{

    return studentLevel;

}

Aucun commentaire:

Enregistrer un commentaire