Hello there good people of the cpluspluss forums.
I am currently writing code for a program that is supposed to take two different digital clock timestamps (hh mm ss), compare them and find out which is the earlies one/latest one, then calulate the difference between them.
I am really new to this kind of stuff, and i have encountered many snags so far.
Can someone take a look at what i have so far? i would really appreciate any feedback/help.
The problem is that it won't compile. line 49 gives me an error (typename not allowed) for the struct. Also, there is an error for the ({) in line 53 and 54. I am wondering if this is my own doing or my compiler. I am using MS VS.
Thanks for the reply!
Thanks.
Now i need to make it find out which timestamp that is earlier and later or if they are the same, and calculate the time in between them. Does anyone have some helpful tips on this? my head is kinda blank, and its getting late.
Ok, so i tried to figure it out, but it didn't go so well. Read the comments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//continunes from my first post. this is part of the int main
struct diff
std::cout << "Modified:\n" << t1 << "\n" << t2 << std::endl;
{
if (t1>t2) { // This doesn't work at all
diff = (t1-t2); // How?
} elseif (t2>t1) {
diff = (t2-t1);
} elseif (t1==t2) {
diff = 0;
std::cout << "Do you like to modify again? "; /*Here it is supposed to be able to
"restart" from line 18"*/
} while( response2 != 'N' && response2 != 'n'); //if no, terminate
return 0;
}
After line 12, you need to use cin to ask the user, otherwise how will response2 be updated for the while loop condition?
As for lines 5 to 10, look at your indentation style - because of this, you forgot the closing brace on line 11. Also it could all be replaced by diff = std::abs(t2-t1).