fork download
  1. //Maxwell Brewer CS1A Chapter 4, P. 221, #7
  2. //
  3. /***************************************************************
  4.  *
  5.  * CALCULATE TIME
  6.  * ________________________________________________
  7.  *
  8.  * This program will take an input from the user
  9.  * to convert seconds into minutes, hours, and days.
  10.  * _____________________________________________
  11.  * INPUT
  12.  *
  13.  * seconds
  14.  *
  15.  * OUTPUT
  16.  *
  17.  * minutes
  18.  * hours
  19.  * days
  20.  *
  21.  ***************************************************************/
  22.  
  23. #include <iostream>
  24. #include <iomanip>
  25. #include <string>
  26.  
  27. using namespace std;
  28.  
  29. int main() {
  30.  
  31. // Initialization
  32. int seconds;
  33.  
  34. // Display input prompts
  35. cout << "Enter number of seconds:\n";
  36. cin >> seconds;
  37.  
  38. // Output
  39. if(seconds >= 60 && seconds < 3600){
  40. cout << "There are " << (seconds / 60)
  41. << " minutes in " << seconds
  42. << " seconds.\n";
  43. }
  44. else if(seconds >= 3600 && seconds < 86400){
  45. cout << "There are " << (seconds / 3600)
  46. << " hours in " << seconds
  47. << " seconds.\n";
  48. }
  49. else if(seconds >= 86400){
  50. cout << "There are " << (seconds / 86400)
  51. << " days in " << seconds
  52. << " seconds.\n";
  53. }
  54.  
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0.01s 5276KB
stdin
552820000
stdout
Enter number of seconds:
There are 6398 days in 552820000 seconds.