|
-
November 17th, 2015, 04:43 PM
#2
Re: Assistance with enumeration in combination with user-defined functions.
Where are you calling sideTri() to enter the values?
In triangleShape, there is no need to pass the parameters by reference as the values are not being changed. As the type is POD pass by value is fine. Also the parameter shape is not used as the type is the return value.
In the switch statement, the cases should be the various enum names (scalene, noTriangle etc) rather than the numbers.
The switch statement can be easily put in a function. Just have a function called something like displayType(triangleType tType){...} and call it from main() after you have called triangleShape(). In fact you could do something like displayType(triangleShape(a, b, c)); In displayType() just have the switch statement.
In fact you don't need a switch statement at all! You could have an array of the names indexed by the type. Also if you have a struct containing the lengths of the sides then sideTri() could return a type of this struct and then your main program would be just 1 line!
Code:
struct Sides
{
side a, b, c;
};
...
Sides sideTri();
triangleType triangleShape(Sides sides);
void displayType(triangleType tType);
...
int main()
{
displayType(triangleShape(sideTri()));
}
NB How are you determining if the entered side values are actually a triangle?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|