Hello to all. Hope everyone is having a good night. I am turning to the message board because I don't know what any of these error messages mean. Hopefully someone out there can help. This program is supposed to calculate the area of a triangle and tell if it is a right triangle or not. Any help is always appreciated.
John
Can anyone help me out or point me in the right direction.
Calculate area of a triangle and tell if its a right triangle or not using a switch
statement. I am getting error messages on lines
righttriangle.c:45: error: expected expression before âelseâ
righttriangle.c:57: error: expected expression before âelseâ
righttriangle.c:126:9: warning: multi-character character constant
righttriangle.c: In function âcalAreaâ:
righttriangle.c:175: error: âfâ undeclared (first use in this function)
righttriangle.c:175: error: (Each undeclared identifier is reported only once
righttriangle.c:175: error: for each function it appears in.)
righttriangle.c:175: error: expected â;â before â}â token
righttriangle.c: In function âmainâ:
righttriangle.c:175: error: expected declaration or statement at end of input
righttriangle.c:175: error: expected declaration or statement at end of input
righttriangle.c:24: warning: unused variable âhypotenuseâ
righttriangle.c: In function âcalLeg1â:
righttriangle.c:161: warning: control reaches end of non-void function
righttriangle.c: In function âcalLeg2â:
righttriangle.c:166: warning: control reaches end of non-void function
righttriangle.c: In function âcalHypotenuseâ:
righttriangle.c:171: warning: control reaches end of non-void function
righttriangle.c: In function âcalAreaâ:
righttriangle.c:175: warning: control reaches end of non-void function
righttriangle.c: In function âmainâ:
righttriangle.c:175: warning: control reaches end of
Code:
10 #include <stdio.h>
11 #include <math.h>
12
13 /* Function Prototypes */
14 void printMenu();
15 void float calLeg1(float leg2, float hypotenuse);
16
17 void float calLeg2(float leg1, float hypotenuse);
18 void float calHypotenuse(float leg1, float leg2);
19 void float calArea(float leg1, float leg2);
20
21 /* Main Function */
22 int main()
23 {
24 /* InitIalizers for legs and hypotenuse */
25 float leg1 = -1.0, leg2 = -1.0, hypotenuse = -1.0;
26
27 /* Sentinal Controlled loop initializers */
28 int selection = 0;
29 int EXIT_VAL = 10;
30
31 /* Beginning of sentinal controlled loop */
32 while(selection != EXIT_VAL)
33 {
34 /* Print Menu first */
35 printMenu();
36 scanf("%d", &selection);
37
38 /* Switch on menu options */
39 switch(selection)
40 {
41 /* Input leg1 */
42 case '1':
43 {printf( "Enter leg1:");
44 scanf( "%f",&leg1 );
45 if ( leg1 > 0)
46 else printf( "Please enter a positive value for leg1\n");
47 /* Did they enter a positive number? */
48
49 break;
50 }
51
52 /* Input leg2 */
53 case '2':
54 {printf( "Enter leg2:");
55 scanf( "%f",&leg2 );
56
57 if ( leg2 > 0)
58 else printf("Please enter a positive number:";
59 /* Did they enter a positive number? */
60 break;
61 }
62
63 /* Input hypotenuse */
64 case '3':
65 {printf( "Enter hypotenuse:");
66 scanf( "%f",&hypotenuse );
67 if ( hypotenuse > 0)
68 printf( "Please enter a positive value for the hypotenuse\n");
69 /* Did they enter a positive number? */
70 break;
71 }
72
73 /* Calculate leg1 */
74 case '4':
75 {
76 /* If enough values have been inputed to solve for it */
77 if leg1 = calLeg1(leg2, hypotenuse)
78 else printf("Not enough information:");
79
80
81 break;
82 }
83
84 /* Calculate leg2 */
85 case '5':
86 {
87 /* If enough values have been inputed to solve for it */
88 if leg2 = calLeg2(leg1, hypotenuse
89 else printf("Print need more information:");
90 break;
91 }
92
93 /* Calculate hypotenuse */
94 case '6':
95 {
96 /* If enough values have been inputed to solve for it */
97 if hypotenuse = calHypotenuse(leg1, leg2)
98 else printf("Need more information:");
99 break;
100 }
101
102 /* Calculate area and print */
103 case '7':
104 { area = ( leg1 * leg2 )/2;
105 printf("The area is %f\n",area);
106 /* If enough values have been inputed to solve for it
107 * a little more complexe than the other calculates */
108 break;
109 }
110
111 /* Determine if values are a right triangle or not */
112 case '8':
113 { if ( leg 1 * leg1 ) + (leg2 * leg2) = ( hypotenuse * hypotenuse )
114 printf("This is a right triangle\n");
115 else printf("This is not a right triangle\n");
116 /* Make sure you handle all possible cases */
117 break;
118 }
119
120 case '9':
121 {printf( "The values are %f\n%f\n%f",leg1,leg2,hypotenuse);
122 /* Display current values for leg1, leg2, and hypotenuse */
123 break;
124 }
125
126 /* Exit Case */
127 case '10':
128 {
129 break;
130 }
131
132 /* If invalid value entered */
133 default:
134 {
135 printf("Invalid Value entered please select again!\n");
136 }
137 }
138 return 0;
139 }
140
141 /* Menu Printing Function */
142 void printMenu()
143 {
144 /* Do work for menu
145 * 1. Input value for leg1
146 * 2. Input value for leg2
147 * 3. Input value for hypotenuse
148 * 4. Calculate leg1
149 * 5. Calculate leg2
150 * 6. Calculate hypotenuse
151 * 7. Calculate area of right triangle
152 * 8. State if values entered is a real right triangle
153 * 9. Display current values of leg1, leg2, and hypotenuse
154 * 10. Exit */
155 }
156
157
158 float calLeg1(float leg2, float hypotenuse)
159 {
160 /* Calculate value for leg1 and return it */
161 }
162
163 float calLeg2(float leg1, float hypotenuse)
164 {
165 /* Calculate value for leg2 and return it */
166 }
167
168 float calHypotenuse(float leg1, float leg2)
169 {
170 /* Calculate value for hypotenuse and return it */
171 }
172
173 float calArea(float leg1, float leg2)
174 {
175 /* Calculate area for triangle and return it */f}