I am new to learning C++. I tried to create a code that is meant to tell time and add minutes to it by using a constructor. However, upon building the code with CodeBlocks, an error is displayed under the scope resolution 'time::time()'.
I tried creating parameters within the constructor but to no avail.
#include<iostream>
using namespace std;
class time
{
private:
int hours,minutes;
public:
time(int);
~time();
void enterTime();
void addMinutes();
void displayTime();
};
time::time()
{
int timehours;
int timeminutes;
cout<<"Enter hours: "<<endl;
cin>>timehours;
if(timehours<00 && timehours>23)
{
cout<<"Invalid Entry of time. Try again."<<endl;
time();
}
else
timehours==00;
cout<<"Enter minutes: "<<endl;
cin>>timeminutes;
if(timeminutes<0 && timeminutes>59)
{
cout<<"Invalid Entry of time. Try again."<<endl;
time();
}
else
timeminutes==00;
cout<<"Initial Time: "<<timehours<<": "<<timeminutes<<endl;
}
void time::enterTime()
{
cout<<"Enter hours: "<<endl;
cin>>hours;
if(hours<00 && hours>23)
{
cout<<"Invalid entry of time. Try Again."<<endl;
enterTime();
}
cout<<"Enter minutes: "<<endl;
cin>>minutes;
if(minutes<00)
{
cout<<"Invalid entry of time. Try Again,"<<endl;
enterTime();
}
cout<<"Initial Time:- "<<hours<<": "<<minutes<<endl;
}
void time::addMinutes()
{
if(minutes>60 && minutes%60>0)
{
int addhours,addMin;
addMin=(minutes%60>0);
addhours=(minutes/60);
hours+=addhours;
if(hours>=24)
hours-=24;
}
}
void time::displayTime()
{
cout<<"Updated time:"<<hours<<" :"<<minutes<<" "<<endl;
}
int main()
{
int n;
for(n=0;n<4;n++)
{
time Time[4];
if((n+1)%2==0)
{
Time[n].time();
Time[n].addMinutes();
Time[n].displayTime();
}
else
{
Time[n].enterTime();
Time[n].addMinutes();
Time[n].displayTime();
}
}
return 0;
}