Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

inputting time

This topic is 1922 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to input the time in hours minutes and seconds in the form of 2.15.8 and then add the value to a second value in the same form and output the answer in the form of 4.15.10 I am thinking about using cin or getche() here is the code I am working on.

int
 
 
main()
{
 
 
int hours,minutes,seconds;
cout << 
 
"Enter first amount: ";
 
cout << 
 
"Enter second amount: ";
?
cout << 
 
"Output total: " << minutes << endl;
system(
 
"pause");
 
 
return 0;
}

 

Share this post


Link to post
Share on other sites
Advertisement

no my code is not formatted like above code

here is my code in proper format

int main()

{int hours,minutes,seconds;

cout << "Enter first amount: ";

 

cout << "Enter second amount: ";

?

 

cout << "Output total: " << minutes << endl;

system("pause");

return 0;

}

my question is how do I input a value like 6.10.15 and add to a value like 2.10.5 and output a value like 8.20.20

Share this post


Link to post
Share on other sites

well, you read them in using cin, if you want to pull them from the standard input.

 

In this case, its fairly trivial since you have delimiters between the numbers which are non-integral.

int x, y, z;
char c;
std::cin>>x>>c>>y>>c>>z;

 

Alternatively, read in a line and use a stringstream to parse it... similar behavior as previous one though.

 

Alternatively to that use a regular expression: "\d+\.\d+\.\d+"

Share this post


Link to post
Share on other sites

cool I was thinking of using cin as well but I was confused as to how to implement the char variables, thanks for all  your help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!