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

Hi, I need help with this C++ programming problem: Write a second ConvertToInche

ID: 3768195 • Letter: H

Question

Hi, I need help with this C++ programming problem:

Write a second ConvertToInches() with two double parameters, numFeet and numInches, that returns the total number of inches. Ex: ConvertToInches(4.0, 6.0) returns 54.0 (from 4.0 * 12 + 6.0).

Here is the template of the problem please use it:

#include <iostream>
using namespace std;

double ConvertToInches(double numFeet) {
return numFeet * 12.0;
}

int main() {
double totInches = 0.0;

totInches = ConvertToInches(4.0, 6.0);
cout << "4.0, 6.0 yields " << totInches << endl;

totInches = ConvertToInches(5.9);
cout << "5.9 yields " << totInches << endl;
return 0;
}

Please explain your code of choice as well. Thanks!

Explanation / Answer

Here is the code for you. If you have any further queries, just revert here.

#include <iostream>
using namespace std;
double ConvertToInches(double numFeet) {   //It takes single parameter.
return numFeet * 12.0;                   //Just returns the parameter multiplied by 12, as 1 foot = 12 inches.
}
double ConvertToInches(double numFeet, double numInches)   //It takes two parameters.
{
return numFeet * 12.0 + numInches;       //Just returns the summation of first parameter multiplied by 12, and the second parameter.
}
int main() {
double totInches = 0.0;                   //Initialize inches to 0.
totInches = ConvertToInches(4.0, 6.0);   //Calls the function ConvertToInches with 2 parameters, first parameter being feet, second parameter being inches.
cout << "4.0, 6.0 yields " << totInches << endl;   //Prints the returned value of the previous called function.
totInches = ConvertToInches(5.9);       //Calls the function ConvertToInches with 1 parameter, itself being the feet.
cout << "5.9 yields " << totInches << endl;       //Prints the returned value of the previous called function.
return 0;
}

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