Undeclared Variable In a Class?

Nov 22, 2017 at 3:08am
Hey! I'm trying to use the get/set functions in a class to return a hidden variable, but keep getting the use of undeclared identifier in the getMinutes and getSeconds.

As far as I know I have set up the private variable (sec, min) then used setMinutes/setSeconds and getMinutes/getSeconds but keep getting this error.


Any help is appreciated!

class LengthOfTime {

private:
int min, sec;

public:
int totalTime, normal=0;

LengthOfTime(){
}

LengthOfTime(int mintues, int seconds){
min = mintues;
sec = seconds;
}

void normalize(int min, int sec){ //works
normal = (min*60)+sec;
min = normal/60;
sec = normal%60;
cout << "the normalized time is "<<min<<":"<<sec<<endl;
}
int setMinutes(int minutes){
min = minutes;
return 0;
}
int setSeconds(int seconds){
sec = seconds;
return 0;
}
int getMinutes(){
return minutes;
}
int getSeconds(){
return seconds;
}

int TotalTime(){
totalTime=(min*60)+sec;
cout << "Total Time: "<<totalTime;
return 0;
}
void printLenghtOfTime(){ // works
cout << "The current time is: "<< min<<":";
if (sec<10) {
cout<< "0" << sec<<endl;
}
if (sec>9) {
cout << sec<<endl;
}
}

};[/code]
Nov 22, 2017 at 3:53am
Your get functions return "minutes" and "seconds" but your variables are named "min" and "sec"
The variables you are trying to return don't exist.
Topic archived. No new replies allowed.