Here is an ex of a problem I'm having difficutly with. I need to make up a program that does the following:

asks user for the number of seconds and the number of miles traveled

program should convert the given number of seonds into different units of time in years/days/hours/minutes/seconds and the average speeds in both miles per hour (mph) and feet per second (ft/s)

using the following conversions:

1 mile= 5280 ft
1 year= 365 days
1 day = 24 hours
1 hour=60 min
1 min=60 secs

I only started learning C++ last week and I'm still not getting it. Someone please help I don't know where to start and sadly I forgot my C++ book at home.

## Recommended Answers

start here. Sadly, we can't do a lot for you if you don't have your text book, unless you can remember how to program.

``````int main()
{
// your code goes here
}``````

It would be good if you could get you book back.

``````#include<iostream>
using namespace std;

int main()
{
float sec = 9.5;
float days;
days = (sec/(365*24*60*60));
cout<< days;
return 0;
}``````

## All 5 Replies

start here. Sadly, we can't do a lot for you if you don't have your text book, unless you can remember how to program.

``````int main()
{
// your code goes here
}``````

Here is an ex of a problem I'm having difficutly with. I need to make up a program that does the following:

asks user for the number of seconds and the number of miles traveled

program should convert the given number of seonds into different units of time in years/days/hours/minutes/seconds and the average speeds in both miles per hour (mph) and feet per second (ft/s)

using the following conversions:

1 mile= 5280 ft
1 year= 365 days
1 day = 24 hours
1 hour=60 min
1 min=60 secs

I only started learning C++ last week and I'm still not getting it. Someone please help I don't know where to start and sadly I forgot my C++ book at home.

you need to use the I/O functions that display and receive data.
Once that is done, you will need a couple of mathematical operations to get the right result. alternatively you could create subroutines for each possible conversion but this maybe a bit tricky for you since you forgot your book at home.

It would be good if you could get you book back.

``````#include<iostream>
using namespace std;

int main()
{
float sec = 9.5;
float days;
days = (sec/(365*24*60*60));
cout<< days;
return 0;
}``````

Hey mate, you probably want something like the following code. I'm also a C++ newbie, so this was a good learning experience for me as well.

``````#include <iostream>
using namespace std;

int main() {

float seconds, minutes, hours, days, years;
float distance_miles, speed_mph, speed_fps;

// Get time and distance from user
cout << "Enter number of seconds: ";
cin >> seconds;
cout << "Enter number of miles travelled: ";
cin >> distance_miles;

// Perform unit conversions:
minutes = seconds/60;
hours = minutes/60;
days = hours/24;
years = days/365;
speed_mph = distance_miles/hours;
speed_fps = (distance_miles*5280)/seconds;

// Output results from time conversions
cout << seconds << " seconds = "
<< minutes << " minutes = "
<< hours << " hours = "
<< days << " days = "
<< years << " years" << endl;

// Output results from speed conversions
cout << "speed = " << speed_mph << " miles/hour = "
<< speed_fps << " feet/second" << endl;
}``````

> I'm also a C++ newbie, so this was a good learning experience for me as well.
Unfortunately, you learnt how to do it (good), and the OP learnt that persistence will sometimes get you a free lunch (or in this case, homework on a plate). This is not good.

Are you going to do their next homework as well?
What about their job later on?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.