To begin, the code that I have got up to this point is below.
The calculator does everything I want it to, minus the fact that it still includes negative numbers in its calculations. I would like for it to do nothing if the number presented as the radius is less than zero, yet still calculate if the number is non-negative. However, I am having issues with using an if statement. I have not used these before, as I am really just a beginner. I just need a push in the right direction. Do I need to have an "else"? Any help is greatly appreciated!
#include <stdio.h>
int radius, area;
main()
{
printf("Enter radius: ");
scanf("%d", &radius);
{
if (&radius > -1); {
area = (int)(3.14159 * radius * radius);
printf("Area = %d\n", area);}
else {
return(0); }
}
return(0);
}
Aucun commentaire:
Enregistrer un commentaire