0

//I need help please?

#include<stdio.h>
#include<iostream.h>

class Time
{
	public:
		Time();
		~Time();
		void setTime(int, int, int);
		void printMilitary();
		void printStandard();
	private:
		int hour, minute, second;
};

void Time::printMilitary()
{
	cout<<"Military time: "<<hour<<minute<<second;
}

Time::Time()
{
	hour=minute=second=0;
}

Time::~Time()
{
	cout<<endl<<"Destructor code.";
}

void main()
{
	Time wakeup, samplePM;
	wakeup.setTime(6, 5, 0);
	samplePM.setTime(15, 30, 24);
	cout<<"I wake up at";
	wakeup.printMilitary();
	cout<<"\nIn standard time: ";
	wakeup.printStandard();
	cout<<"\nIn Snack time: ";
	samplePM.printMilitary();
	cout<<"\nIn standard time: ";
	samplePM.printStandard();
	getch();
}

//It has an error, it says:

//function 'getch' should return a value
//Why did the compiler treat it as a function and are the header files lacking or what?
//thanks

Edited by WaltP: Added CODE Tags -- Learn to use them.

3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by WaltP
0

You got a few things to take care of which may or may not directly be related to your problem:

1. Please in the future, when you post on the forum, wrap your code with code tags.
2. void main() is bad, for many reasons. instead, use int main() which will return 0 upon successful termination of your program.
3. How did you even make it this far without deriving objects from the standard namespace? Try adding using namespace std; on the 3rd line of your code.
4. Format your code nicely. Just like you indent between paragraphs when you write a paper, you should indent blocks of similar code.

Edited by Clinton Portis: n/a

2

//Why did the compiler treat it as a function...

Because it IS a function.

... and are the header files lacking or what?

No, you are lacking the header file.

But why do you want to use a non-standard C function when a standard C++ function works just fine? Use cin.get() Also, main() is an int function, not a void function. See this

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.