hi!every one !

J

jim

#include<stdio.h>
#include<math.h>
void main()
{
float x,y,z;
scanf("%f,%f\n",&x,&y) ;

z=(fabs(x)-2)*(fabs(x)-2)+(fabs(y)-2)*(fabs(y)-2)-1;


if(z<=1e-6)
{
printf("the height of the dot is 10 m .\n");
}
else


printf("the height of the dot is 0 m .\n");



}
i wote it,but it can not run rightly!
would u tell me what is wrong with it ?
thanks
 
P

pemo

jim said:
#include<stdio.h>
#include<math.h>
void main()
{
float x,y,z;
scanf("%f,%f\n",&x,&y) ;

z=(fabs(x)-2)*(fabs(x)-2)+(fabs(y)-2)*(fabs(y)-2)-1;


if(z<=1e-6)
{
printf("the height of the dot is 10 m .\n");
}
else


printf("the height of the dot is 0 m .\n");



}
i wote it,but it can not run rightly!
would u tell me what is wrong with it ?
thanks

Which inputs do you expect to produce which outputs? What is the code
trying to solve for you?
 
R

Richard Heathfield

jim said:
#include<stdio.h>
#include<math.h>
void main()

main returns int, not void. So make that:

int main(void)
{
float x,y,z;
scanf("%f,%f\n",&x,&y) ;

scanf returns a value, which you need to check, in case something went
wrong.
z=(fabs(x)-2)*(fabs(x)-2)+(fabs(y)-2)*(fabs(y)-2)-1;

What is this supposed to do? Let's assume that x has the value 3.0, and y
has the value 4.0.

fabs(3.0) is 3.0.

fabs(3.0) - 2 is 1.0.

(fabs(3.0) - 2) * (fabs(3.0) - 2) is 1.0.

fabs(4.0) is 4.0.

fabs(4.0) - 2 is 2.0.

(fabs(4.0) - 2) * (fabs(4.0) - 2) is 4.0.

(fabs(3.0) - 2) * (fabs(3.0) - 2) + (fabs(4.0) - 2) * (fabs(4.0) - 2) is
5.0.

(fabs(3.0) - 2) * (fabs(3.0) - 2) + (fabs(4.0) - 2) * (fabs(4.0) - 2) - 1 is
4.0.

So z takes the value 4.0.

Is that what you were expecting?

if(z<=1e-6)
{
printf("the height of the dot is 10 m .\n");
}
else


printf("the height of the dot is 0 m .\n");

main returns int, so add:

return 0;
}
i wote it,but it can not run rightly!

What do you mean by "run rightly"? What is it supposed to do?
 
R

Robin Haigh

jim said:
#include<stdio.h>
#include<math.h>
void main()
{
float x,y,z;
scanf("%f,%f\n",&x,&y) ;

[snip]

Your problem might just be the scanf format. scanf is very picky, not easy
to master, and possibly not worth it. For now though, changing the format
to just "%f%f" might do what you want
 
R

Rod Pemberton

Robin Haigh said:
jim said:
#include<stdio.h>
#include<math.h>
void main()
{
float x,y,z;
scanf("%f,%f\n",&x,&y) ;

[snip]

Your problem might just be the scanf format. scanf is very picky, not easy
to master, and possibly not worth it. For now though, changing the format
to just "%f%f" might do what you want

Nice call. With a TTF, I can't even see that comma...

RP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Hi! 0
Hi! 0
Hi 1
Hi! 0
Hi Everyone! 2
Hi coders 5
Hi From Canada 3
Hi all 0

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,500
Latest member
ArianneJsb

Latest Threads

Top