Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote