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

Need help on c++ Homework. Need help updating code from previous assignment to t

ID: 3607653 • Letter: N

Question

Need help on c++ Homework.

Need help updating code from previous assignment to this assignment above.

here is the code from previous assignment below

#include

using namespace std;

double mercury(double oWeight) {

return oWeight * 0.38;

}

double venus(double oWeight) {

return oWeight * 0.91;

}

double mars(double oWeight) {

return oWeight * 0.38;

}

double moon(double oWeight) {

return oWeight * 0.17;

}

int main() {

double userInput;

again:

cout << "Enter weight on earth: " << endl;

cin >> userInput ;

if(userInput <= 0) {

cout << "Can't go below 0, Please try again" << endl;

goto again;

}

do {

cout << "*****************************" << endl;

cout << "* Main Menu:" << endl;

cout << "* Select planet to convert earth's weight to:" << endl;

cout << "1) Mercury" << endl;

cout << "2) Venus" << endl;

cout << "3) Mars" << endl;

cout << "4) Moon" << endl;

cout << "5) All planets" << endl;

cout << "6) Exit" << endl;

cout << "*****************************" << endl;

int userselection;

cout << "choose #:";

cin >> userselection;

switch(userselection) {

case(1):

cout << "Earth's weight: " << userInput << " lbs."

<< endl << "Mercury's weight: " << mercury(userInput) << " lbs."

<< endl;

break;

case(2):

cout << "Earth's weight: " << userInput << " lbs."

<< endl << "Venus weight: " << venus(userInput) << " lbs."

<< endl;

break;

case(3):

cout << "Earth's weight: " << userInput << " lbs."

<< endl << "Mars's weight: " << mars(userInput) << " lbs."

<< endl;

break;

case(4):

cout << "Earth's weight: " << userInput << " lbs."

<< endl << "Moon's weight: " << moon(userInput) << " lbs."

<< endl;

break;

case(5):

cout << "Earth's weight: " << userInput << " lbs."

<< endl << "Mercury's weight: " << mercury(userInput) << " lbs."

<< endl << "Venus weight: " << venus(userInput) << " lbs."

<< endl << "Mars weight: " << mars(userInput) << " lbs."

<< endl << "Moon's weight: " << moon(userInput) << " lbs."

<< endl;

break;

case(6):

cout << "Goodbye!" << endl;

break;

default:

cout << "Wrong selection. Try again..." << endl;

}

}while(userInput!=6);

return 0;

}

Update to Program to Pass Values by Reference for the program. Use switch case for menu syntax. Do not use If/Else Ladder. Do-While Menu Update. Update your program to us a menu that will not close until the user selects quit option. Program should contain a menu Enter 1. For Mercury Weight thty welit Enter 2. For Venus Weight (After the user enters 1 the program will output weight converted to Venus weight.) Enter 3. For Mars Weight Enter 4. For Earth Moon Weight Enter 5: For all Conversions Enter 6: To Quit

Explanation / Answer

#include <iostream>
using namespace std;

//use pointers as arguments in functions
double mercury(double *oWeight) {
return *oWeight * 0.38;
}
double venus(double *oWeight) {
return *oWeight * 0.91;
}
double mars(double *oWeight) {
return *oWeight * 0.38;
}
double moon(double *oWeight) {
return *oWeight * 0.17;
}
int main() {
double userInput;
again:
cout << "Enter weight on earth: " << endl;
cin >> userInput ;
if(userInput <= 0) {
cout << "Can't go below 0, Please try again" << endl;
goto again;
}
do {
cout << "*****************************" << endl;
cout << "* Main Menu:" << endl;
cout << "* Select planet to convert earth's weight to:" << endl;
cout << "1) Mercury" << endl;
cout << "2) Venus" << endl;
cout << "3) Mars" << endl;
cout << "4) Moon" << endl;
cout << "5) All planets" << endl;
cout << "6) Exit" << endl;
cout << "*****************************" << endl;
int userselection;
cout << "choose #:";
cin >> userselection;
if(userselection == 6)
break;
else
{
switch(userselection) {
case(1):
cout << "Earth's weight: " << userInput << " lbs."
<< endl << "Mercury's weight: " << mercury(&userInput) << " lbs."
<< endl;
break;
case(2):
cout << "Earth's weight: " << userInput << " lbs."
<< endl << "Venus weight: " << venus(&userInput) << " lbs."
<< endl;
break;
case(3):
cout << "Earth's weight: " << userInput << " lbs."
<< endl << "Mars's weight: " << mars(&userInput) << " lbs."
<< endl;
break;
case(4):
cout << "Earth's weight: " << userInput << " lbs."
<< endl << "Moon's weight: " << moon(&userInput) << " lbs."
<< endl;
break;
case(5):
cout << "Earth's weight: " << userInput << " lbs."
<< endl << "Mercury's weight: " << mercury(&userInput) << " lbs."
<< endl << "Venus weight: " << venus(&userInput) << " lbs."
<< endl << "Mars weight: " << mars(&userInput) << " lbs."
<< endl << "Moon's weight: " << moon(&userInput) << " lbs."
<< endl;
break;
case(6):
cout << "Goodbye!" << endl;
break;
default:
cout << "Wrong selection. Try again..." << endl;
}
}
}while(userInput!=6);
return 0;
}

Output:

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