fork download
  1. // Elaine Torrez Chapter 2 P. 221, #7
  2. /**************************************************************************
  3.  * TIME CALCULATOR
  4.  * ------------------------------------------------------------------------
  5.  * This program asks the user to enter a number of seconds. If the number
  6.  * is large enough, it converts the seconds into minutes, hours, or days:
  7.  *
  8.  * 60 seconds = 1 minute
  9.  * 3600 seconds = 1 hour
  10.  * 86400 seconds = 1 day
  11.  *
  12.  * It then displays the conversion based on the value entered.
  13.  * ------------------------------------------------------------------------
  14.  * INPUT
  15.  * seconds : Number of seconds entered by the user
  16.  *
  17.  * OUTPUT
  18.  * The equivalent time in minutes, hours, or days (if applicable)
  19.  **************************************************************************/
  20.  
  21. #include <iostream>
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. int seconds; // User input for total seconds
  27.  
  28. // Get input
  29. cout << "Enter the number of seconds: ";
  30. cin >> seconds;
  31.  
  32. // Check ranges with if/else if
  33. if (seconds >= 86400)
  34. cout << "That is " << (seconds / 86400.0) << " days.\n";
  35. else if (seconds >= 3600)
  36. cout << "That is " << (seconds / 3600.0) << " hours.\n";
  37. else if (seconds >= 60)
  38. cout << "That is " << (seconds / 60.0) << " minutes.\n";
  39. else
  40. cout << "That is less than one minute.\n";
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0.01s 5288KB
stdin
45
stdout
Enter the number of seconds: That is less than one minute.