eriktorres
IS-IT--Management
I have been working on the following code. I use the Unix gcc compiler, which compiles the code OK. Using Dev C++ just gives me an error indicating that the application must close. The error I get in gcc is 'segmentation fault', but using g++ I also get 'segmentation fault', after I run a.out, execute, and type in my three sides. Any ideas?
Code:
**********************************************************
#include <stdio.h>
#include <math.h>
/****Demostrates Declerations****/
double aside;
double bside;
double cside;
double sides;
int num_scan;
//float area;
void calcsides(void);
//void calcarea(void);
void inputsides(void);
void scannum(void);
/****Main Function****/
main(){
calcsides();
// calcarea();
inputsides();
printf("Here is the area of the triangle");
printf("%lf.", sqrt((sides*((sides - aside)*(sides - bside)*(sides - cside)))));
}
/****Function Definitions****/
void inputsides(void){
printf("**********************************************************\n");
printf("Please enter three sides A, B, and C to calculate the area\n");
printf("of the triangle, negative numbers will not be calculated!\n");
printf(">>");
scannum();
while(aside < 0.00 || bside < 0.00 || cside < 0.00){
while(getchar() != '\n'){
}
printf("You have entenred an incorrect number!");
scannum();
}
calcsides();
}
void calcsides(void){
sides = ((aside + bside + cside) / 2);
}
//void calcarea(void){
// area = sqrt(sides*((sides - aside)*(sides - bside)*(sides - cside));
// }
void scannum(void){
scanf("%lf %lf %lf", aside, bside, cside);
}
*********************************************************
Code:
**********************************************************
#include <stdio.h>
#include <math.h>
/****Demostrates Declerations****/
double aside;
double bside;
double cside;
double sides;
int num_scan;
//float area;
void calcsides(void);
//void calcarea(void);
void inputsides(void);
void scannum(void);
/****Main Function****/
main(){
calcsides();
// calcarea();
inputsides();
printf("Here is the area of the triangle");
printf("%lf.", sqrt((sides*((sides - aside)*(sides - bside)*(sides - cside)))));
}
/****Function Definitions****/
void inputsides(void){
printf("**********************************************************\n");
printf("Please enter three sides A, B, and C to calculate the area\n");
printf("of the triangle, negative numbers will not be calculated!\n");
printf(">>");
scannum();
while(aside < 0.00 || bside < 0.00 || cside < 0.00){
while(getchar() != '\n'){
}
printf("You have entenred an incorrect number!");
scannum();
}
calcsides();
}
void calcsides(void){
sides = ((aside + bside + cside) / 2);
}
//void calcarea(void){
// area = sqrt(sides*((sides - aside)*(sides - bside)*(sides - cside));
// }
void scannum(void){
scanf("%lf %lf %lf", aside, bside, cside);
}
*********************************************************