Title: Bgamed's Timercount
Description: just a timer dude
BGamed - June 11, 2006 11:47 AM (GMT)
well its just a sort of stopwatch, made it cause I wanted to do some revision of classes again, there are no bugs as far as I know...
You can use it for whatever you want...:P
| CODE |
//include headerfiles #include <windows.h> #include <iostream> //initialize the namespaces using namespace std; //declare variables int secondsshow=0; int goal; //initialize the class class updater { public: void goalupdater(); }; //class updater>goalupdater sourcecode void updater::goalupdater() { for (int x=goal;x>=secondsshow;secondsshow++) { system("cls"); cout<<secondsshow<<" seconds of the "<<goal<<" have already past."<<endl; Sleep(1000); } cout<<endl<<"Timer ended at: \a"; system("echo %time%"); cout<<endl; cout<<"Press any key to exit..."; system("pause >nul"); } int main() { system("color 0A"); system("title BGamed Developer his timecounter"); //intro code cout<<"BGamed Developments presents..."; Sleep(1500); system("cls"); cout<<"His own timecounter"; Sleep(1500); system("cls"); cout<<"Please specify how many seconds you want me to count...\n"<<" -"; cin>>goal; cout<<endl<<"Hit enter to start the counting..."; system("pause > nul"); updater update; update.goalupdater(); }
|
;)
gamehawk Edit: You forgot the int in front of main(), I fixed it for you.
gamehawk - June 11, 2006 01:37 PM (GMT)
You didn't really need to use classes, and it wouldn't be a good thing to do in a program that wasn't for practice. Since your using it to practice classes though, it's cool. Nice job.
Cheers,
gamehawk :)
BGamed - June 11, 2006 04:43 PM (GMT)
I know it's possible too without classes...
but em, why do I have to use the
before main, actually? :huh:
I know a lot of people do, but I'd wonder why...
gamehawk - June 11, 2006 04:56 PM (GMT)
Well, Dev-C++'s compiler isn't the most exact. A lot of other compilers (like my VC++ compiler) don't recognize it. The reason is, that notice the return 0 (can't be done with void), and parameters are usually passed in and out of the main function for command line programs. Dev-C++ is kind of bad in that way, it compiles mistakes so your program works, but starts some rather nasty coding habits. Other compilers wouldn't even recognize the program, and it can be a pain for others (to fix stuff) if your sharing your source.
Cheers,
gamehawk :)
BGamed - June 14, 2006 05:14 AM (GMT)
I see....
well, thanks for letting me know by then :)
Neken - June 14, 2006 03:36 PM (GMT)
| CODE |
//initialize the namespaces using namespace std; //declare variables int secondsshow=0; int goal; //initialize the class class updater { public: void goalupdater(); }; |
You are not "initializing the namespaces" you are just telling the compiler that you use the std:: namespace.
You are not "initializing the class" you are declaring it. There's a HUGE difference ...
Class initialization is the constructor.
Global variables are a bad habit.
Stenny - June 14, 2006 08:08 PM (GMT)
| QUOTE |
| Global variables are a bad habit. |
I'm beginning to why classes are so much used then, now the reason for not using them though.
BGamed - June 14, 2006 08:15 PM (GMT)
I know I actually declare them, but its a bad habit : I always say initialize instead of declare, mostly I remember it way too late, about 2 hours after it.... :P
Stenny - June 15, 2006 06:44 AM (GMT)
so declaring is like creating initializing setting it up?
gamehawk - June 15, 2006 11:48 AM (GMT)
It took you two hours to make this? Anyway, try using a bunch of classes and functions instead of globals. Your program could do this:
| CODE |
class Dog { public: const int returnAge; Dog(); ~Dog(); private: unsigned short int age; }; Dog::Dog() { age=3; } ~Dog::Dog() { } const Dog::returnAge() { return age; }
|
Then create an instance of your class and every time you need the variable you can access it from anywhere by calling returnAge.
Cheers,
gamehawk :)
Cheers,
gamehawk :)
BGamed - October 14, 2006 01:15 AM (GMT)
No , of course I didn't used 2 whole hours for something like this <_<
(I'm back :o )
EDIT: else i would have already changed it :)
you see....it is always TOO late, when i remember it, won't forget it anymore tough :)