I am a student trying to make a simple program to get the area of a triangle, square, rectangle, and circle using functions using C language. Unfortunately, my program won't run even though I double checked the syntax and debugged. Listed below is my code for reference:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float triangle(float b, float h)
{
float triangle;
triangle=0.5*b*h;
return triangle;
}
float square(float s)
{
float square;
square=s*s;
return square;
}
float rectangle(float l, float w)
{
float rectangle;
rectangle=l*w;
return rectangle;
}
float circle(float r)
{
float circle;
circle=3.14*r*r;
return circle;
}
main()
{
float base, height, side, length, width, radius;
printf("Triangle Area:\nEnter Base and Height:");
scanf("%f%f", &base, &height);
printf("Area of the Triangle= %f", triangle(base, height));
printf("\nSquare Area:\nEnter Side:");
scanf("%f", &side);
printf("Area of the Square= %f", square(side));
printf("\nRectangle Area:\nEnter Length and Width:");
scanf("%f%f", &length, &width);
printf("Area of the Rectangle= %f", rectangle(length, width));
printf("\nCircle Area:\nEnter Radius:");
scanf("%f", &radius);
printf("Area of the Circle= %f", circle(radius));
return 0;
}
Edit: Sorry for not getting back to you guys on time. I followed one of your suggestions to put int main(void){} instead of just main(){}.
I believe there is a problem with my compiler because when I try to run the program it would just show the compilation results and that there is nothing wrong with my syntax. I decided to not to input 355.0 / 113.0 to replace 3.14 for pi. I am using WindowsOS platform for as requested.
I cannot attach a photo because I do not have enough reputation but this is what appears in the compiler:
Compilation results...
- Errors: 0
- Warnings: 0
- Output Filename: (Personal Information)
- Output Size: 157.9794921875 KiB
- Compilation Time: 0.73s
Should I change something in the code or try something else? Thank you!