Create independent return functions that calculate each planetary body independently.
In main() create a menu that controls the program.
The program should bring receive input only in main() and pass values to other parts of the program.
I did this, but my teacher said, its printing because I put cout in void function. What is the best way to do it?
[code]
Put the code you need help with here.
#include <iostream>
using namespace std;
void marsWeight (int earth){
float mars=0.38*earth;
cout <<"\nThe weight in mars is "<<mars<<endl;
}
float mercuryWeight(int earth){
float mercury =0.38*earth;
cout <<"\nThe weight in mercury is "<<mercury<<endl;
return mercury;
}
float venusWeight(int earth){
float venus = 0.91*earth;
cout <<"\nThe weight in Venus is "<<venus<<endl;
return venus;
}
float moonWeight(int earth){
float moon=0.083*earth;
cout <<"\nThe weight in moon is "<<moon<<endl;
return moon;
}
int main(){
int earth;
cout<<"Enter your weight in earth: ";
cin>>earth;
if (earth <=0)
cout<<"Input 0 or less than 0"<<endl;
else{
#include <iostream>
int foo() {
// do you see any I/O in this function?
return 42;
}
int main() {
// pass return value of function to cout
std::cout << "The answer is " << foo() << '\n';
// or store the value and use it later
int answer = foo();
std::cout << "The answer is still" << answer << '\n';
return 0;
}
Edit: Why is your 'mars' different from all other celestial bodies?