C++ cout problem

Hello. I'm having a bit of difficulty with my program. Basically, you enter hours, minutes and seconds and it will calculate the equivalent amount of seconds. My question is, the output says, "Seconds: xxxx"

I want it to say: x hours, y minutes and z seconds = xxxx seconds.

Here is my code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

// Headers and Library
#include "stdafx.h"
#include <iostream>
#include <math.h>

using namespace std;

// Main Function
int main()

{
	// Variables
	double hours = 0;
	double minutes = 0;
	double seconds = 0;
	double output = 0;

	// Input and Output for Hours, Minutes and Seconds
	cout << "Please enter the number of hours: ";
	cin >> hours;

	cout << "Please enter the number of minutes: ";
	cin >> minutes;

	cout << "Please enter the number of seconds: ";
	cin >> seconds;

	// Caclulate 
	output = (hours * 3600) + (minutes * 60) + seconds;

	// Output
	cout << endl << "Seconds: " << output << endl;

	return 0;
}


Thanks!
Last edited on
I don't see any problems.
Just modify your cout
How do I go on about doing this? helios, please re-read the post. Thank-you.

My output right now is, "Seconds: xxxx"

I want it to be x hours, y minutes and z seconds...etc..

How do I do that exactly?

Sorry I'm new. Whatever input the user inputs, how do I show that in place of x, y and z?

Thanks!
Just what you've got there but add something like:

1
2
cout  << hours << " hours, " << minutes << " minutes, "
         << seconds << " seconds. Make: " << output << " Seconds."; endl
Hours/minutes/seconds dont really have to be of type double, since in the user would enter something like:
5 hours 25 minutes and 15 seconds
you can have a long int to take up the output:
long int output;
Topic archived. No new replies allowed.