| | |
Noob Help needed for Time problem
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2006
Posts: 67
Reputation:
Solved Threads: 0
I am trying to write a simple program in c++ to take a beginning delivery time in 24 hour time and an ending delivery time then taking 25% off that time(making the end time 25% sooner). For example, i'd have a user enter in 0900 for start time and 1030 for an end time. The output for the new end time is 1007. My code sort of works, but I don't know how to incorporate the 25% sooner data.
Here it is:
I need help to figure how to make the 'improved' time affect hours and not just minutes.
Here it is:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> using namespace std; int main() { const int SIXTY = 60; const int HUNDRED = 100; double IMPROVEMENT = .25; // This is to multiply the 25% better time //int start_time = 0; int start_time; cout << "Enter start time: " << endl; cin >> start_time; int start_hours = start_time / HUNDRED; int start_minutes= start_time % HUNDRED; int end_time; cout << "Enter end time: " << endl; cin >> end_time; int end_hours = (end_time / HUNDRED); int end_minutes = (end_time % HUNDRED); int total_minutes = (end_minutes - start_minutes) * IMPROVEMENT; int total_hours = end_hours - start_hours; total_hours = total_hours / SIXTY; cout.fill('0'); cout << "The new end time is: " << setw(2) << total_hours << setw(2) << total_minutes << endl; return 0; }
Last edited by matrimforever; Sep 17th, 2006 at 11:20 pm.
Logically...you have a start time and an end time stored in variables.
create a third variable to hold the total time (start time - end time)
multiply the total time by 0.75 (totalTime*0.75) and store it in a new variable
add the calculated time to the start time
mathematically...
((end time - start time) * 0.75) + start time
create a third variable to hold the total time (start time - end time)
multiply the total time by 0.75 (totalTime*0.75) and store it in a new variable
add the calculated time to the start time
mathematically...
((end time - start time) * 0.75) + start time
Ah..I just saw the bottom part...the minute hour thing is kind of tricky
convert your start and end time to minutes...so that all of your calculations are done in minutes...
the final step would be to convert the minutes back into an hour:minute format
so hours would be calculated by
int hours = newTime / 60
int minutes = newTime % 60
and your time output would be
cout << hours << ":" << munutes;
convert your start and end time to minutes...so that all of your calculations are done in minutes...
the final step would be to convert the minutes back into an hour:minute format
so hours would be calculated by
int hours = newTime / 60
int minutes = newTime % 60
and your time output would be
cout << hours << ":" << munutes;
Kind of...the best thing to do is write down the process first
get start time in military format
convert start time to minutes
int startMin = ((startTime / 100) * 60) + startTime % 100
get end time in military format
convert end time to minutes
int endMin = ((endTime / 100) * 60) + endTime % 100
Calculate total time
TotalMin = (endMin - startMin)
Calculate improved time
ImproveMin = TotalMin * 0.75
calculate improved time
fastTime = startMin + ImproveMin
Convert the faster time to military format
fastHour = fastTime / 60
fastMin = fastTime % 60
milTime = (fastHour * 100) + (fastMin)
This is just an example...your final output can be done in a couple of ways.
get start time in military format
convert start time to minutes
int startMin = ((startTime / 100) * 60) + startTime % 100
get end time in military format
convert end time to minutes
int endMin = ((endTime / 100) * 60) + endTime % 100
Calculate total time
TotalMin = (endMin - startMin)
Calculate improved time
ImproveMin = TotalMin * 0.75
calculate improved time
fastTime = startMin + ImproveMin
Convert the faster time to military format
fastHour = fastTime / 60
fastMin = fastTime % 60
milTime = (fastHour * 100) + (fastMin)
This is just an example...your final output can be done in a couple of ways.
![]() |
Similar Threads
- Help the IT noob, i experience laggy and delay online game. (Networking Hardware Configuration)
- some help needed..changing of time format from 12hour format to 24hour format (Perl)
- Problem with Generic Host Process popup and Internet Explorer opening very slow (Viruses, Spyware and other Nasties)
- No "Data & Time" Function (Windows 95 / 98 / Me)
Other Threads in the C++ Forum
- Previous Thread: Determine if a certain ivalue is in a string
- Next Thread: Problem with VC++
Views: 1473 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





