| | |
Time Difference solution?
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2008
Posts: 9
Reputation:
Solved Threads: 0
Having just a few problem with bring the difference of time times back into this form HH: MM
S. I am required to you % , and fill the remaining space with 0's. Some of my code is just previous rambling that I turned into comments. Any ideas would be of great help.
#include <iostream>
#include <iomanip>
int main()
{
int hrs1 = 0;
int min1 = 0;
int sec1 = 0;
int hrs2 = 0;
int min2 = 0;
int sec2 = 0;
int time1 = 0;
int time2 = 0;
int x = 0;
std::cout << "enter a first time";
std::cin>> time1;
std::cout << "enter a second time";
std::cin>> time2;
hrs1 = time1 / 10000 * 60 * 60;
min1 = time1 / 10000 % 100 * 60;
sec1 = time1 % 100;
hrs2 = time2 / 10000 * 60 * 60;
min2 = time2 / 10000 % 100 * 60;
sec2 = time2 % 100;
x = (hrs1 + min1 + sec1) - (hrs2 + min2 + sec2);
//hrs = time2 / 10000 * 60 * 60;
//min = time2 / 10000 % 100 * 60;
//sec = time2 % 100;
//time1 = time1 / 10000 * 60 * 60 + time1 / 10000 % 100 * 60 + time1 % 100;
//time2 = time2 / 10000 * 60 * 60 + time2 / 10000 % 100 * 60 + time2 % 100;
//timeRemaining = time1 - time2 ;
std::cout << std::setfill('0') << x % 100000 /60 << ":" << x % 1000 / 10 << ":" << x % 60;
S. I am required to you % , and fill the remaining space with 0's. Some of my code is just previous rambling that I turned into comments. Any ideas would be of great help. #include <iostream>
#include <iomanip>
int main()
{
int hrs1 = 0;
int min1 = 0;
int sec1 = 0;
int hrs2 = 0;
int min2 = 0;
int sec2 = 0;
int time1 = 0;
int time2 = 0;
int x = 0;
std::cout << "enter a first time";
std::cin>> time1;
std::cout << "enter a second time";
std::cin>> time2;
hrs1 = time1 / 10000 * 60 * 60;
min1 = time1 / 10000 % 100 * 60;
sec1 = time1 % 100;
hrs2 = time2 / 10000 * 60 * 60;
min2 = time2 / 10000 % 100 * 60;
sec2 = time2 % 100;
x = (hrs1 + min1 + sec1) - (hrs2 + min2 + sec2);
//hrs = time2 / 10000 * 60 * 60;
//min = time2 / 10000 % 100 * 60;
//sec = time2 % 100;
//time1 = time1 / 10000 * 60 * 60 + time1 / 10000 % 100 * 60 + time1 % 100;
//time2 = time2 / 10000 * 60 * 60 + time2 / 10000 % 100 * 60 + time2 % 100;
//timeRemaining = time1 - time2 ;
std::cout << std::setfill('0') << x % 100000 /60 << ":" << x % 1000 / 10 << ":" << x % 60;
Your problem statement is not very clear. In what form is the time entered by the user? Total seconds, 24-hour time, StarDate?
How does division by 10,000 come into play?
How does division by 10,000 come into play?
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
OK. I don't usually see or do this type problem with seconds included.
You're on a right track, but perhaps doing too much in parts. Consider the input time 082517 (8:25:17am)
Dividing by 10000 you get result 8, the hour. No multipying by 60's needed (unless you're thrn trying to find how many seconds that number of hours is.)
Store the result of time % 10000 and you have the remaining minutes&seconds.
Divide that by 100 to find the minutes (25). Mod by 100 to find remaining seconds (17). You're done.
When it comes to displaying the time, you have options on how to display leading zeros when needed. I'll leave you to work on that for a while.
You're on a right track, but perhaps doing too much in parts. Consider the input time 082517 (8:25:17am)
Dividing by 10000 you get result 8, the hour. No multipying by 60's needed (unless you're thrn trying to find how many seconds that number of hours is.)
Store the result of time % 10000 and you have the remaining minutes&seconds.
Divide that by 100 to find the minutes (25). Mod by 100 to find remaining seconds (17). You're done.
When it comes to displaying the time, you have options on how to display leading zeros when needed. I'll leave you to work on that for a while.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- ASM 2-D Bubble Sort!! (Assembly)
- Is it time for a reformat? (Windows NT / 2000 / XP)
- Internet Connection sharing problems (Networking Hardware Configuration)
- Updating a file: setting the offset (Perl)
- Macromedia Releases MX 2004 (Graphics and Multimedia)
- XP Boot problems due to virus? (Viruses, Spyware and other Nasties)
- Counting the amount of letters in a phrase! (C++)
- Need help with HTMl Table echoing? (PHP)
Other Threads in the C++ Forum
- Previous Thread: Looping Problem---Urgent Please help
- Next Thread: Trying to learn from error messages(general error c10100b1)
Views: 1440 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






