I am trying to write this basic program to convert minutes to hours and minutes. I can get it to work but I need the singular minute and hour when the output is one and the plural otherwise and this is messing me up. I know I can use if else statements, but I am trying to do it with the conditional ternary as that's where I am in learning C++. Can anyone see what I am obviously missing? Thanks for any help! Here is my code:
#include <iostream>
using namespace std;
int convert_to_hour (int);
int convert_to_min (int);
int main()
{
int totalmin;
cout <<"This program converts minutes to hours and minutes. \n";
cout <<"Please enter a number of minutes (an integer) to be converted: \n";
cin >>totalmin;
cout << totalmin << " minutes equals " << (convert_to_hour(totalmin)== 1?"1 hour and ": " hours and ") << (convert_to_min(totalmin)==1? "1 minute.": " minutes.") <<endl;
return 0;
}
int convert_to_hour (int totalmin)
{
int hour=(totalmin / 60) % 24;
return (hour);
}
int convert_to_min (int totalmin)
{
int min = (totalmin % 60);
return (min);