Skip to content

Commit

Permalink
Added aditional documentation for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldotwav committed Feb 8, 2024
1 parent 743e5ef commit 23d825d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ This C program classifies triangles as Equilateral, Isosceles, Scalene, or Inval

**Complexity Analysis:** Time Complexity: O(1), Space Complexity: O(1).

### Benefits Over Alternative Approaches
## Benefits Over Alternative Approaches

This approach emphasizes input validation, readability, and efficiency by using well-defined functions for each task and constants for triangle types, which enhances maintainability and reduces error likelihood.
21 changes: 15 additions & 6 deletions Source.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ int main(void) {
return 0;
}

/* This function loops until the user enters a non-negative number */
int getValidSide(int sideNumber) {
int validLength = 0;

Expand All @@ -89,10 +90,7 @@ int getValidSide(int sideNumber) {
return validLength;
}

/*
This function takes in three side lengths and determines the type of triangle formed
E = Equilateral, S = Scalene, I = Isosceles, and N = None (or invalid)
*/
/* This function takes in three side lengths and determines the type of triangle formed */
char getTriangleType(int side1, int side2, int side3) {
char type = INVALID;
/* First, check if the side lengths can form a valid triangle */
Expand Down Expand Up @@ -128,15 +126,15 @@ double getArea(int side1, int side2, int side3) {
*
* Case 1: User Inputs 0 / Negative Number for Side Length
*
* ```cpp
* ```c
* Enter Side #1: -2
*
* ERROR: Length Must Be Greater Than 0
* ```
*
* Case 2: Cannot Form Valid Triangle From User-Input Lengths
*
* ```cpp
* ```c
* Enter Side #1: 1
* Enter Side #2: 2
* Enter Side #3: 3
Expand All @@ -150,8 +148,19 @@ double getArea(int side1, int side2, int side3) {
* Enter 'Y' for Yes and 'N' for No:
* ```
*
* Case 3: Invalid User-Input for Re-Running Program
*
* ```c
* Would you like to run the program again?
* Enter 'Y' for Yes and 'N' for No: a
*
* ERROR: Invalid Selection
*
* Would you like to run the program again?
* Enter 'Y' for Yes and 'N' for No: Y
*
* Enter Side #1:
* ```
*
*
*
Expand Down

0 comments on commit 23d825d

Please sign in to comment.