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).
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.
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.
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.
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.