Λοιπόν, σκοπός του προγράμματος είναι να υπολογίζει και να εμφανίζει στην οθόνη την περίμετρο ενός τριγώνου και το εμβαδόν με χρήση δομών και συναρτήσεων
Το έφτιαξα, τρέχει νομίζω σωστά αλλά η συνάρτηση εισόδου τιμών μετά την είσοδο της γωνίας Α, ζητάει όλα τα υπόλοιπα 2 φορές ακόμα και αν η τιμή που δώθηκε δεν είναι αρνητική....
Το ίδιο και η δομή που υπολογίζει το εμβαδό
Δεν ζητάω την λύση απλά να μου δείξετε το πρόβλημα(please

- Κώδικας: Επιλογή όλων
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char title[20];
int a;
int b;
int c;
int h;
int per;
float em;
}triangle;
triangle inputFunction(triangle trigwno)
{
printf ("Dwste ton titlo tou trigwnou: ");
scanf (" %s", trigwno.title);
printf("Dwste to mhkos ths pleyras a: ");
scanf(" %d",&trigwno.a);
while (trigwno.a<0) //oso to h timh pou dw8hke einai arnhtikh ektupwsh la8ous kai ksanadiavasma timhs...
{
printf("\nTo mhkos twn pleurwn den ginetai na einai arnhtikos ari8mos \nDwste ksana to mhkos ths pleyras a: ");
scanf("%d",&trigwno.a);
}
printf("Dwste to mhkos ths pleyras b: ");
scanf(" %d",&trigwno.b);
while (trigwno.b<0);
{
printf("\nTo mhkos twn pleurwn den ginetai na einai arnhtikos ari8mos \nDwste ksana to mhkos ths pleyras b: ");
scanf("%d",&trigwno.b);
}
printf("Dwste to mhkos ths pleyras c: ");
scanf(" %d",&trigwno.c);
while (trigwno.c<0);
{
printf("\nTo mhkos twn pleurwn den ginetai na einai arnhtikos ari8mos \nDwste ksana to mhkos ths pleyras c: ");
scanf("%d",&trigwno.c);
}
printf("Dwste to upsos toy trigwnou: ");
scanf(" %d",&trigwno.h);
while (trigwno.h<0);
{
printf("\nTo upsos den ginetai na einai arnhtikos ari8mos \nDwste ksana to upsos toy trigwnou: ");
scanf("%d",&trigwno.h);
}
trigwno.em=0;
trigwno.per=0;
return trigwno; //epistrofh dedomenwn ths sunarthshs sthn main
}
void printFunction(triangle trigwno) //sunarthsh ektupwshs
{
--------------------Δουλέυει σωστά--------------------
}
int perimeterFunction(triangle trigwno) //sunarthsh upologismou ths perimetrou
{
--------------------Δουλέυει σωστά--------------------
}
float areaFunction(triangle trigwno) //sunarthsh upologismou emvadou
{
char answer;
printf("Poia gwnia einai h vash tou trigwnou? (a,b,c)\n");
scanf (" %c",&answer);
if ((answer!="a") || (answer!="b") || (answer!="c"))
{
printf ("\nSfalma! Sigoureuteite oti to CAPS LOCK einai off kai h glwssa EN \nPoia gwnia einai h vash tou trigwnou? (a,b,c): ");
scanf ("%s",&answer);
}
switch (answer)
{
case 'a':
trigwno.em = 1.0/2.0*trigwno.a*trigwno.h;
break;
case 'b':
trigwno.em = 1.0/2.0*trigwno.b*trigwno.h;
break;
case 'c':
trigwno.em = 1.0/2.0*trigwno.c*trigwno.h;
break;
}
return trigwno.em;
}
int main()
{
triangle trigwno;
trigwno=inputFunction(trigwno);
trigwno.per= perimeterFunction(trigwno);
trigwno.em= areaFunction(trigwno);
printFunction(trigwno);
return 0;
}
Ίσως άσχετο άλλα χρησιμοποιώ το Code::Blocks και τον GCC