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 ;
}
|