Z
zemir
Hi, this is my first message on this group............ In these days i
am studing C language and i wrote some codes. Today i am writing a
small programm to calculate the perimeter and the area of a circle;
this is:
#include <stdio.h>;
#include <math.h>;
float area(float r)
{ /*define area
function*/
return(r*r*3.14);
}
float perimeter(float r)
{ /*define perimeter
function*/
return(2*3.14*r);
}
void main() {
system("cls");
float r=0; int c=121 /*define radius and c variable used to
control the behaviour of the
program;
it is set to 121 value (y
char)*/
printf("This programm calculate Area and Perimenter of a Circle");
do {
printf("\n\nPlease insert radius value (in cm): ");
scanf("%f", &r); /*input of the radius value*/
if(r>0) {
printf("Area is cm2: ");
printf("%.2f", area(r)); /
*call area function*/
printf("\nPerimeter is cm: ");
printf("%.2f", perimeter(r)); /*call
perimeter function*/
} else printf("Value must to be a valid number");
printf("\nDo you want to continue? (y or elsewhere to exit)");
c=getch();
} while(c==121);
printf("\nEND\n");
}
I use Tcc compiler on Windosw XP. The program works fine, i wrote it
to get positive value number else it print a warning message. However
also in the case i make a mistake and write a string or a char it
display a warning message but if i try to remake the calculate it does
not work as well as i should want
Why?.
I have tried to resete r value to zero:
else {
r=0;
printf("Value must to be a valid number");
}
but it is the same.
I hope in your help.
Thanks!
am studing C language and i wrote some codes. Today i am writing a
small programm to calculate the perimeter and the area of a circle;
this is:
#include <stdio.h>;
#include <math.h>;
float area(float r)
{ /*define area
function*/
return(r*r*3.14);
}
float perimeter(float r)
{ /*define perimeter
function*/
return(2*3.14*r);
}
void main() {
system("cls");
float r=0; int c=121 /*define radius and c variable used to
control the behaviour of the
program;
it is set to 121 value (y
char)*/
printf("This programm calculate Area and Perimenter of a Circle");
do {
printf("\n\nPlease insert radius value (in cm): ");
scanf("%f", &r); /*input of the radius value*/
if(r>0) {
printf("Area is cm2: ");
printf("%.2f", area(r)); /
*call area function*/
printf("\nPerimeter is cm: ");
printf("%.2f", perimeter(r)); /*call
perimeter function*/
} else printf("Value must to be a valid number");
printf("\nDo you want to continue? (y or elsewhere to exit)");
c=getch();
} while(c==121);
printf("\nEND\n");
}
I use Tcc compiler on Windosw XP. The program works fine, i wrote it
to get positive value number else it print a warning message. However
also in the case i make a mistake and write a string or a char it
display a warning message but if i try to remake the calculate it does
not work as well as i should want
Why?.
I have tried to resete r value to zero:
else {
r=0;
printf("Value must to be a valid number");
}
but it is the same.
I hope in your help.
Thanks!