cant figure out what im doing wrong

#include <iostream>
#include <string>

using namespace std;

class Time
{
protected:
int hr, min , sec;
string zone;


public:


Time(int h, int m, int s) {hr = h; min = m; sec = s;}


void setHour();
void setMinute();
void setSeconds();
int getHour(){return hr;};
int getMinute(){return min;};
int getSeconds(){return sec;};
void addHour();
void addMinute();
void addSeconds();

void printTime();
};


class ExtTime : public Time
{
public:
ExtTime(int h, int m, int s):Time(h,m,s){}
void timeZone(int, int, int);
void printTime();

private:
string zone;
};

// main.cpp

#include <iostream>
#include <string>
#include "timeZone.h"
using namespace std;


int main()
{

Time myTime;
myTime.setHour();
myTime.setMinute();
myTime.setSeconds();
int h = myTime.getHour();
int m = myTime.getMinute();
int s = myTime.getSeconds();

cout << "The hour is " << h << " and the minute is " << m << "and the second is " << s << endl;
myTime.printTime();
cout << endl;
myTime.addHour();

cout << "After adding 1 hour\n";
myTime.printTime();
cout << endl;

myTime.addMinute();
cout << "After adding 1 minute\n";
myTime.printTime();
cout << endl;

myTime.addSeconds();
cout << "After adding 1 second\n";
myTime.printTime();
cout << endl;
ExtTime newTime(h,m,s);


newTime.timeZone(h,m,s);


return 0;

}

//clockType.cpp
#include "timeZone.h"

void Time::setHour()
{
cout << "Enter the hour: ";
cin >> hr;
}

void Time::setMinute()
{
cout << "Enter the minutes: ";
cin >> min;
}
void Time::setSeconds()
{
cout << "Enter the seconds: ";
cin >> sec;
}

void Time::addHour()
{
hr++;
if(hr == 24)
hr = 0;
}

void Time::addMinute()
{
min++;
if(min == 60)
{
hr++;
min = 0;
if(hr == 24)
hr = 0;
}
}
void Time::addSeconds()
{
sec++;
if( sec == 60)
{
min++;
min = 0;
if(min == 60)
min = 0;
}
}
void Time::printTime()
{
cout << "In Eastern Standard Time the time is: ";
if(hr > 24)
cout << "0";
cout << hr << ":";
if(min > 59)
cout << "0";
cout << min << ":";
if( sec > 59)
cout << "0";
cout << sec;
}

void ExtTime::timeZone(int, int, int)
{
cout << "Enter time zone (EST, PST, MST, CST): ";

cin >> zone;

if (zone == "PST" || zone == "pst")
cout << "The time is: " << (hr-3) << ":" << getMinute() << getSeconds() << endl;
if (zone == "EST" || zone == "est")
cout << "The time is: " << hr << ":" << getMinute() << getSeconds() << endl;
if (zone == "CST" || zone == "cst")
cout << "The time is: " << (hr-1) << ":" << getMinute() << getSeconds() << endl;
if (zone == "MST" || zone =="mst")
cout << "The time is: " << (hr-2) << ":" << getMinute() << getSeconds() << endl;
}
What does it do that you don't like, or what does it not do that you wish it did?
Its not working it was before I added seconds to the mix and then it stopped working and gave me these errors

exit status 1
main.cpp: In function 'int main()':
main.cpp:11:11: error: no matching function for call to 'Time::Time()'
Time myTime;
^~~~~~
In file included from main.cpp:4:
timeZone.h:16:5: note: candidate: 'Time::Time(int, int, int)'
Time(int h, int m, int s) {hr = h; min = m; sec = s;} //calling function
^~~~
timeZone.h:16:5: note: candidate expects 3 arguments, 0 provided
timeZone.h:6:7: note: candidate: 'Time::Time(const Time&)'
class Time
^~~~
timeZone.h:6:7: note: candidate expects 1 argument, 0 provided
timeZone.h:6:7: note: candidate: 'Time::Time(Time&&)'
timeZone.h:6:7: note: candidate expects 1 argument, 0 provided
The class Time has no default constructor. Only this constructor:
Time(int h, int m, int s) {hr = h; min = m; sec = s;}
So the only way to create a Time object is to use that constructor. The one that takes three parameters.


While I'm here, there is a bug in your addSeconds() function that is most easily fixed by making it add to the minutes by calling addMinute instead of fiddling around with the minute value. Don't replicate code. If you have a function that adds a minute, and you want to add a minute, call the function. Don't write out another version of the same code. Likewise for adding an hour.
I feel so dumb Thank you so much I kept trying multiple different things I dont know why I didnt think of that. for the addSeconds(),

would it look like this
void Time::addSeconds()
{
sec++;
if( sec == 60)
{
min++
addMinute();

}
No.

min++;
addMinute();

This is adding two minutes, isn't it? That's bad.
Ok I got it!! thank you again!!
Topic archived. No new replies allowed.