I've gotten used to writing all the classes in the main but I also learned that you can create new class and headers. That is where I become confused. This is what i have to give some background info. I use CodeBlocks.
void Regular::setarea(float a)
{
area = a;
}
void Regular::setsides(float c)
{
sides = c;
}
void Regular::setperimeter(float p)
{
perimeter = p;
sum1 = perimeter * sides;
}
float Regular::getsides()
{
return sides;
}
float Regular::getarea()
{
return area;
}
float Regular::getperimiter()
{
return sum1;
}
void Regular::setanswer()//needs to be a void because you are not returning anything
{
answer = (area * sum1);
answer /= 2; // i think you meant that
}
float Regular::getanswer()
{
return answer;
}
and the source would keep your main function.
Note: Though I do suggest 2 changes I only tested the code to compile and not to run correctly. You should also have a constructor, both a default and overloaded.
Prefer double rather than float. The latter looses precision quickly, e.g. 9.99 * 9.99 looses 1 significant figure.
You should not have the setarea, setperimeter, functions, the respective get functions should do the calculation. And they are considerably more involved that what you have now.
setanswer is also dodgy, it shouldn't be there at all.
sum1 is a poor name for a variable, change to something more meaningful.