Urgent i c++: Please correct the following program so the total time is correctl
ID: 3604984 • Letter: U
Question
Urgent i c++:
Please correct the following program so the total time is correctly displayed, right now it always displays 0.
//ch 6
//organizing codes into units called fucntions
//calculte total time needed when traveling xx distance at xx mph
//#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
void totaltime(double mph, double distance);
void totaltime(double mph, double distance)
{
double total_time = (distance/mph);
return;
}
int main()
{
double mph;
double distance;
double total_time;
cout << "Enter mph: " << endl;
cin >> mph;
cout << "Enter distance in miles: " << endl;
cin >> distance;
totaltime(mph, distance);
cout << "total time is: " << total_time << endl;
//system("pause");
return 0;
}
Explanation / Answer
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
double totaltime(double mph, double distance);
int main()
{
double mph;
double distance;
double total_time;
cout << "Enter mph: " << endl;
cin >> mph;
cout << "Enter distance in miles: " << endl;
cin >> distance;
total_time = totaltime(mph, distance);
cout << "total time is: " << total_time << endl;
//system("pause");
return 0;
}
double totaltime(double mph, double distance)
{
double total_time = distance/mph;
return total_time;
}
OUTPUT
Enter mph: 1234
Enter distance in miles: 12
total time is: 0.00972447
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.