#include<stdio.h>
#include<math.h>
#define PI 3.1416
#define g 9.81
void main(void)
{
/*initialisation*/
int u,alpha,MAXHEIGHT;
/*input*/
printf("Enter the initial velocity and the angle (in degree):");
scanf("%f%f",&u,&alpha);
/*calculation*/
MAXHEIGHT=(u*u*(pow(sin(alpha*PI/180.0),2))/(2*g));
/*output*/
if (alpha>=0 && alpha<=180)
{
printf("The maximun height is %.4ld\n",MAXHEIGHT);
}
else
{
printf("input angle should lie between 0 and 180\n");
} // end else
} // end main
for some reason,when i type in alpha as any number,the else statement comes out.can anyone plz help me?new to C programing,thxs.
This is a C++ forum, not a C forum. Please use code tags.
Please check the scanf documentation on this site. I doubt %f is correct to read an int value.
1stly,thxs to all of you for replying.i am new n dun understand the rules so plz try to tolerate with me.i tried replacing the int with float.the calculation went wrng,and when i types the else statement conditions,noting comes out.And this is a C++,i think,cause i chose it on the select screen,and it says C++.And what is code tags?
here is the program
#include<stdio.h>
#include<math.h>
#define PI 3.1416
#define g 9.81
void main(void)
{
/*initialisation*/
float u,alpha,MAXHEIGHT;
/*input*/
printf("Enter the initial velocity and the angle (in degree):");
scanf("%f%f",&u,&alpha);
/*calculation*/
MAXHEIGHT=(u*u*(pow(sin(alpha*PI/180.0),2))/(2*g));
/*output*/
if (alpha>=0 && alpha<=180)
{
printf("The maximun height is %.4ld\n",MAXHEIGHT);
}
else if(alpha<0 && alpha>180)
{
printf("input angle should lie between 0 and 180\n");
} // end else
} // end main