Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse errors

Status
Not open for further replies.

goncrazybbaksoon

Programmer
Jan 30, 2003
6
US
I'm getting parse errors on three lines, and I don't see anything wrong with them. I haven't put the code in to display the time yet, so disregard that. The parse errors are on these lines:

Clock.addseconds(int sec);
Clock.pm('P');
Clock.pm('A');

Can anybody tell me what the problem is?
The whole code is below:

//Clock

#include <iostream.h>
#include <stdlib.h>

class Clock //new data type
{
public:
void addseconds(int sec);
void showtime(char ampm);

Clock()
{
hour = 12;
min = sec = 0;
pm = false;
}

private:
int sec; //00-59 seconds
int min; //00-59 minutes
int hour; //1-12 hours
bool pm; //am or pm
};

int main()
{
Clock clock;
Clock ampm;

for(int i=0; i<86400; i++)
{
Clock.addseconds(int sec);
Clock.showtime(char ampm);
}

cout<<&quot;:&quot;;

system(&quot;PAUSE&quot;);
return 0;
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
void Clock::addseconds(int sec)
{
if(sec < 59)
{
sec++;
}
else
{
sec = 0;
if(min < 59)
{
min++;
}
else
{
min = 0;
if(hour < 12)
{
hour++;
}
else
{
hour = 1;
if(hour==12)
{
pm = true; //change to pm
}
}
}
}
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
void Clock::showtime(char ampm)
{
char pm;

if(pm==true)
{
Clock.pm('P');
}
else
{
Clock.pm('A');
}
}
 
Clock.addseconds(int sec);

Two things: 1) Clock is a class, not an object. Since addseconds is not a static function, you need to call it off a specific clock object, not off the class itself. 2) you're trying to declare sec inside the argument list. You just can't do that.

Clock.pm('P');
Clock.pm('A');

See #1 above.
 
instantiate a clock class:
Clock myClock;

then do myClock.addseconds(value);

however, pm doesn't seem to be a function of your clock class? so that'd be a problem too. The weevil of doooooooooom
-The eagle may soar, but the weasel never gets sucked up by a jet engine (Anonymous)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top