469,649 Members | 1,716 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

Programming Forum

Hello Guys,
I've developed a forum for programmers and shareware developers to
discuss projects, sales, promotion and more. Please take a look if you
will at http://forum.codecall.net

Thanks,
Jordan

Jun 12 '06 #1
1 1894
On 12 Jun 2006 09:01:09 -0700, jd*******@ionicware.com wrote in
comp.lang.c++:
Hello Guys,
I've developed a forum for programmers and shareware developers to
discuss projects, sales, promotion and more. Please take a look if you
will at http://xxxxx.xxxxxxxx.xxx
Utter and absolute garbage.

Example from
http://xxxxx.xxxxxxxx.xxx/c-c/201-ca...program-c.html, pasted
with "> " quotes, even though it was not part of the OP's post:

================ #include
Obviously somebody does not know how to convert header names to show
up properly in HTML.
float add(float,float);
float sub(float,float);
float product(float,float);
float divide(float,float);
void main()
Oops, undefined behavior in C, an ill-formed program in C++.
{
float n1,n2;
char sym,choice;
printf("This Program is a program for calculator\n\n");
scanf("%f%c%f",&n1,&sym,&n2);
Doesn't actually prompt for input, nor explain the expected format of
that input. Doesn't take into account the poor behavior of scanf()
with live user input, let alone the potential undefined behavior.
if(sym=='+')
printf("\n%f",add(n1,n2));
if(sym=='-')
printf("\n%f",sub(n1,n2));
if(sym=='*')
printf("\n%f",product(n1,n2));
if(sym=='/')
printf("%f",divide(n1,n2));
printf("\nDo you wish to continue[y/n]");
scanf("%s",&choice);
Uses "%s" conversion specifier to scanf() with the address of a single
character, guaranteed memory overwrite and undefined behavior.
if(choice=='y'||choice=='Y')
main();
Calls main() recursively to loop?!? Yikes!?!
}
float add(float m1,float m2)
{
return(m1+m2);
}
float sub(float m1,float m2)
{
return(m1-m2);
}
float product(float m1,float m2)
{
return(m1*m2);
}
float divide(float m1,float m2)
{
return(m1/m2);
}


The output may not appear without a terminating '\n', and the leading
'\n' is of questionable utility.

What a waste of web space.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jun 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Jst | last post: by
42 posts views Thread by Kevin Spencer | last post: by
1 post views Thread by jdelozier | last post: by
4 posts views Thread by Maciek | last post: by
2 posts views Thread by technica | last post: by
reply views Thread by technica | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.