Connecting Tech Pros Worldwide Forums | Help | Site Map

hi!every one !

jim
Guest
 
Posts: n/a
#1: Mar 14 '06

i am new to c and turboc.
and i am learning it .
i hope you can help me .
thanks .


jim
Guest
 
Posts: n/a
#2: Mar 14 '06

re: hi!every one !


#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

pemo
Guest
 
Posts: n/a
#3: Mar 14 '06

re: hi!every one !


jim wrote:[color=blue]
> #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[/color]

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

--
==============
Not a pedant
==============


Richard Heathfield
Guest
 
Posts: n/a
#4: Mar 14 '06

re: hi!every one !


jim said:
[color=blue]
> #include<stdio.h>
> #include<math.h>
> void main()[/color]

main returns int, not void. So make that:

int main(void)
[color=blue]
> {
> float x,y,z;
> scanf("%f,%f\n",&x,&y) ;[/color]

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

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?

[color=blue]
>
> 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");
>
>[/color]

main returns int, so add:

return 0;
[color=blue]
>
> }
> i wote it,but it can not run rightly![/color]

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

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Vladimir S. Oka
Guest
 
Posts: n/a
#5: Mar 14 '06

re: hi!every one !


On Tuesday 14 March 2006 11:06, jim opined (in
<1142334360.707113.214270@i40g2000cwc.googlegroups .com>):[color=blue]
> i am new to c and turboc.
> and i am learning it .
> i hope you can help me .[/color]

And your question was? Once you have one, you're more than welcome to
post it here. Before you do, please read and heed:
<http://cfaj.freeshell.org/google/>. This one
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c> is also useful
if you want to avoid friction with the regulars.

--
BR, Vladimir

Power is danger.
-- The Centurion, "Balance of Terror", stardate 1709.2

Robin Haigh
Guest
 
Posts: n/a
#6: Mar 14 '06

re: hi!every one !



"jim" <abc2005211@gmail.com> wrote in message
news:1142334580.906419.265670@j52g2000cwj.googlegr oups.com...[color=blue]
> #include<stdio.h>
> #include<math.h>
> void main()
> {
> float x,y,z;
> scanf("%f,%f\n",&x,&y) ;
>
>[snip][/color]

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

--
RSH



Rod Pemberton
Guest
 
Posts: n/a
#7: Mar 14 '06

re: hi!every one !



"Robin Haigh" <ecl6rsh@leeds.ac.uk> wrote in message
news:dv6ipr$fsr$1@newsg1.svr.pol.co.uk...[color=blue]
>
> "jim" <abc2005211@gmail.com> wrote in message
> news:1142334580.906419.265670@j52g2000cwj.googlegr oups.com...[color=green]
> > #include<stdio.h>
> > #include<math.h>
> > void main()
> > {
> > float x,y,z;
> > scanf("%f,%f\n",&x,&y) ;
> >
> >[snip][/color]
>
> Your problem might just be the scanf format. scanf is very picky, not[/color]
easy[color=blue]
> to master, and possibly not worth it. For now though, changing the format
> to just "%f%f" might do what you want[/color]

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

RP


jim
Guest
 
Posts: n/a
#8: Mar 15 '06

re: hi!every one !


thank u very much
and i have knewn what is wrong with it

Closed Thread