Trouble with Program

This program is supposed to Write a function that gets weight factor from the user and use that factor to return the planet (planets enum type) with that factor.
• Write another function that takes that value of planets type (returned above) as an argument and prints the name of the planet using planets enumeration type in cases of switch statement.

Im getting errors that say identifier not found for both of my functions. here is the code


// Andre Taylor December 10 2010
// This Program
// Extends Program 8 to create an enumeration type for planets.
// has a function that gets weight factor from the user and uses that factor to return the planet (planets enum type) with that factor.
// has another function that takes that value of planets type (returned above) as an argument and prints the name of the planet using planets enumeration type in cases of switch statement.
// Makes sure that you ask the user if user wants to continue (use do while loop).


#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
enum Planet{Mercury,Venus,Earth,Moon,Mars,Jupiter,Saturn,Uranus,Neptune,Pluto};
Planet thisPlanet;
double factor;
int main()
{



cout<<"Ohiyo! Please enter the factor of the planet"<<endl;
cin>>factor;
thisPlanet =GetFactor(factor);//error here
GetPlanet(thisPlanet);//error here

return 0;
}


Planet GetFactor(double factor)
{
if(factor==4155)
{
return Mercury;
}
else if(factor== .8975)
{
return Venus;
}
else if(factor==1.0)
{
return Earth;
}
else if(factor==.166)
{
return Moon;
}
else if(factor==3507)
{
return Mars;
}
else if(factor==2.5374)
{
return Jupiter;
}
else if(factor==1.0677)
{
return Saturn;
}
else if(factor==0.8947)
{
return Uranus;
}
else if(factor==1.1794)
{
return Neptune;
}
else if (factor==.0899)
{
return Pluto;
}
else

cout<<"Factor is not one of the planets"<<endl;
}




void GetPlanet(Planet)
{
switch(thisPlanet)
{
case Mercury: cout<< "The planet is Mercury" <<endl;
break;
case Venus: cout<< "The planet is Venus" <<endl;
break;
case Earth: cout<< "The planet is Earth" <<endl;
break;
case Moon: cout<< "This is the Moon" <<endl;
break;
case Mars: cout<< "The planet is Mars" <<endl;
break;
case Jupiter: cout<<"The planet is Jupiter"<<endl;
break;
case Saturn: cout<< "The planet is Saturn"<<endl;
break;
case Uranus: cout<<"The planet is Uranus"<<endl;
break;
case Neptune: cout<<"The planet is Neptune"<<endl;
break;
case Pluto: cout<<"The planet is Pluto" <<endl;
break;
defualt: cout<<"There is no planet to return"<<endl;
}
}



You need to add a forward declaration for your functions before you call them. So just put your function signatures above your main routine and that should fix it.
Wait I dont understand what you are telling me to do. Please explain in laments terms
closed account (D80DSL3A)
Place the function definitions before the main function instead of after it. The compiler doesn't recognize the functions GetFactor and GetPlanet in main() because they haven't been defined yet.
o ok thank you now i understand.
I put the functions prototypes at the top and its still giving me the same error. Maybe u should try and copy and paste the code then run it with the prototypes at the top to see what im talking about.
closed account (D80DSL3A)
I did that and your program worked fine. I got no errors (but I did get 2 warnings). Note: you are not really passing anything to GetPlanet. The variable of type Planet being passed has no label. The switch statement is using the global variable thisPlanet directly.
Please post back your new code so we can see what you did.
Topic archived. No new replies allowed.