C++ minutes conversion to hours

Hello, something isn't right and I don't see it.
************************************************
Two cars A and B leave an intersection at the same time. Car A travels west at an average speed of x miles per hour and car B travels south at an average speed of y miles per hour.
Write a program that prompts the user to enter:
1. The average speed of Car A and Car B as two separate input statements.
2. The elapsed time (in hours and minutes, separated by a space) after the cars leave the intersection.
o Ex: For two hours and 30 minutes, 2 30 would be entered The program then outputs:
1. The (shortest) distance between the cars.
Hint:
You will need to use the Pythagorean theorem to calculate the distance
*********************************************************************
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 //
//  main.cpp
//  A03
//
//  Created by Giannina Combina on 5/1/19.
//  Copyright © 2019 Giannina Combina. All rights reserved.
//

// Include Headers Files
#include <iostream>
#include <cmath>
int square(int);
using namespace std;

// Main Function

int main ()
{
//Declaring Variables
   double speedcarA;
   double speedcarB;
   int hour;
   int minutes;
   int shortDistance;
    int carADistance;
    int carBDistance;
    int hour_2;
    
// Prompt user for input
cout << "Please enter car A speed:" << endl;
// Read input from user
cin >> speedcarA;

// Prompt user for input
    cout << "Please enter car B speed:" << endl ;
// Read input from user
cin >> speedcarB ;

// Prompt user for elapsed time
cout << "Please enter time in hours and minutes" << endl;
    cin>> hour >> minutes;
   
//Convert hours to minutes
   
    hour_2 = minutes / 60;
    
// Find out carA distance
carADistance = speedcarA * (hour + hour_2);
carBDistance = speedcarB * (hour + hour_2);

// Get the shortest distance between carA and carB
//  c^2 = sqrt (a^2 + b^2)
    shortDistance =sqrt((carADistance * carADistance) + (carBDistance * carBDistance));

    // Out put result
    cout << " the shortest distance would be:" << " " << shortDistance << " " <<"miles" << endl;
    
    return 0 ;

}
> //Convert hours to minutes
> hour_2 = minutes / 60;

Total minutes is hours*60 + minutes
something isn't right and I don't see it.
Why do you calculate integer?

BTW, how about calculate the relative speed and multiply this with the elapsed time, saves one multiplication (... yes I know, the gain is not mensurable and so there is no gain worth a change.)
@salem

I am trying to convert MINUTES TO HOURS AND NOT HOURS TO MINUTES.
@MIKESTGT

I am so new and you just spoke Chinese to me
Well minutes / 60 will always give you 0 at present, because they're integers.

you just spoke Chinese to me
Chinese is the new English ;)

Back to the subject: To compute the cars distance you first calculate each cars distance from the starting point and next go with this two values to Pythagoras. I would calculate first the speed the two cars go away from each other and then mind the elapsed time to get the distance at that point in time. Pythagoras works not only for length/way/extend/route/stretch/leg (if straight and flat and coplanar) but also for velocity (if not accelerated, if straight in same flat plane) due to theorem of intersecting lines.
Example with figures: Car A goes west by 30 mph, Car B drives south by 40 mph, so they go away from each other by 50 mph. Now, in 6 minutes the distance between the cars is 5 miles. Because I know the relative speed I do not mind any more the speed of a single car (and there was no question where the answer requires it).

Edit: the car's distance or the cars distance?
Last edited on
Topic archived. No new replies allowed.