C++ program that obtains minutes and remaining seconds from an amount of time in seconds
Posted by Samath
Last Updated: November 05, 2014

Write a C++ program for the following scenario. John Rowe has asked you to write a program that obtains minutes and remaining seconds from an amount of time in seconds. For example, 500 seconds contains 8 minutes and 20 seconds. Perform appropriate desk-checking to verify the correctness of your program.
Hint: To get the remainder in C++ use the modulus operator (%). For example 8 % 2 = 0, 8 % 3 = 2.

Sample Output:

 

Here is the Solution to the problem above:

#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
	int enter_second;
	int minutes;
	int second;
	
	
	cout<<"Enter an Integer for seconds: ";
	cin>>enter_second;
	
	minutes = enter_second / 60;
	second = enter_second % 60;
	
	cout<<"Your Answer is: "<<enter_second<<" seconds is "<<minutes<<" minutes and "<<second<<" seconds. "<<endl;
	return 0;
}