|
|
|
#1 (permalink) | ||||||||||||
|
Intel Overclocker
![]() |
PHP Code:
The purpose of this code is to display the current time, and display the time if the seconds were 555550. The result should be something like: Current Time is hh/mm/ss Current Time for 555550 seconds is 10 hours, 19 minutes, 9 seconds. I don't know where to go from here. As with my other threads, any help deserves REP++
__________________
|
||||||||||||
|
|
|
|
|
#2 (permalink) | ||||||||||||
|
Intel Overclocker
![]() |
K so i revised it and here is what i have now
PHP Code:
__________________
|
||||||||||||
|
|
|
|
|
#3 (permalink) | ||||||||||||
|
Intel Overclocker
![]() |
Any suggestion as to what i should do next?
__________________
|
||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
Programmer
![]() |
Seems to work fine. I had to change the time(0) as time because they can't be used as functions.
Code:
#include <iostream>
#include <ctime>
using namespace std;
class Time
{
public:
int hour;
int minute;
int second;
int time;
Time()
{
time = time;
}
Time(int newTime)
{
time = newTime;
}
int getHour()
{
int totalSeconds = time;
int currentSecond = totalSeconds % 60;
int totalMinutes = totalSeconds / 60;
int currentMinute = totalMinutes % 60;
int totalHours = totalMinutes / 60;
return totalHours;
}
int getMinute()
{
int totalSeconds = time;
int currentSecond = totalSeconds % 60;
int totalMinutes = totalSeconds / 60;
int currentMinute = totalMinutes % 60;
return currentMinute;
}
int getSecond()
{
int totalSeconds = time;
int currentSecond = totalSeconds % 60;
return currentSecond;
}
};
int main()
{
Time time;
cout << time.getHour() << ":" << time.getMinute() << ":" << time.getSecond() << endl;
Time time1(555550);
cout << time1.getHour() << ":" << time1.getMinute() << ":" << time1.getSecond() << endl;
cin.get();
return 0;
}
__________________
Steam - KForKorben X-Fire - kforkorben I did Latty's Linux Challenge and I now have tried Linux! ![]() I am 54% addicted to Counterstrike. What about you? 4Ghz
|
|||||||||||||
|
|
|
|
|
#5 (permalink) | |
|
Case Modder
![]() |
Quote:
That change negates the whole purpose of the class. ![]() As written, the class's time data member clashes with the time() function. A better "fix" would be to rename the time data member to totalSeconds. Don't re-fetch the the current time() in your class's member functions i.e. int a t1.getHour(); int b t1.getHour(); a should equal b. Check your algorithms with simpler test code i.e. Time t(61); int h = t.getHour(); int m = t.getMinutes();, etc.
__________________
Rich Custom Wooden Case Builder
|
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|