doubles and ints

R

rohit.x.tripathi

Hello Bill, List
If I can give you one advice, it will be: try another language before
C. C pull you too much to the edge. You need to do everything by hand,
and for you, as we can see, that is too hard to glark. Your problem
isn't really the C syntax, but transform problem in algorithm. Sorry
to say that, but your code doesn't make sense to me, and will probably
make no sense to others. Try some other language to learn how to do
that, and then move to C.

[snip]

I learned Basic many years ago. It was a piece of cake. Algorithms I know
nothing about. Basic itself wasn't a problems but putting things where they
needed to go was a bit.

There I see a problem. Basic is a decent programming language for
middle school, but C is a very different language -- you can hardly
apply BASIC programming paradigms (goto is a classic example) to C and
get away with it on clc.

If you're in the mood to try harder: start with assembler, then move
to C. Trust me, things will make a lot more sense.
 
F

Falcon Kirtaran

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bill said:
Is this valid C syntax ?

double=double/int;

I seem to be having trouble here.

Bill

The short answer is "no". However, I think you mean to ask about:

double b=1;
int c=2;
double a=b/c;

If that is what you meant, you should try to post things that won't
elicit such responses as above. It is indeed valid; division involving
at least one floating point type (float, double, long, long long, etc.)
will have a result of the larger of double or the largest type involved
(so it will never return a float, for instance).

That said, you could assign the value to an int validly, thus rounding
the value down. Also, you could divide two int values such as 2/5, and
the result would be 0 (not 0.4) regardless of whether you assigned it to
an integer or floating point type.

If you didn't already know that, please look up type promotion and demotion.

- --
- --Falcon Darkstar Kirtaran
- --
- --OpenPGP: (7902:4457) 9282:A431

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJIjmtoAAoJEKmxP9YxEE4r5JsP/3U+4KGSQtL8H4vNhDISFclo
bFgkL0xA1AR/xP8u8j6wAckBLIaWXupreBjGc/54ELzn2smAveYfhZTYMuUFYq4X
tjOXkzRiPCkP7yd3XZKSkl44Y04w3rPUw+xtWNbEIPmj0GzsnbSLokfdF8UZEs8N
KBT33A1tliGJvsIDm2+qnuumd3JQfKfdkkpLCB+P5g0CBuQx4r8px6rWhG4l2VbV
IPsxV1+wScku3DsEedipfUQix2Ky849xnLToxTAJxOl1Kb7r6+7X1qJymwb8G5AB
cnViBHH+pNTeE4ZD09BPv8qgCeMun5rR8zMVw5D+my+MHk+ZbOajWbvYtK1XOLdS
Yqp5e+nwi3uoOVmpYhN2CV2hGGz79Nh/c+NQLssAHzpfHke8vgs9GIjpWBBuwRD5
PpRdQGiCsBwYj9VF/2DdcrJugE5iLPRryR4+rtO26bF2Zws8R1Rt4HuUC1wHjZYU
2DGedMEOkEuvD4yO6d/SDqvpIAy/MFQ46fdw4aOuju/rz7dKErKyeyuRR69mazvz
iF8A1KFl3F9kDJiycJYGDz4XcyQk6DBi9Sx1RPdakHfW044yXiOpSX4AGY+mokWA
TbdvyWC+LFOv3Kbdb87zSzEcxO4ajD6qnpHn8kXQIOMe2yYLGz+bGjQMmxjryTat
CKDzG32JMTyJe1cmpffX
=050B
-----END PGP SIGNATURE-----
 
F

Falcon Kirtaran

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bill said:
Walter Roberson said:
No it is not.
[snip]

double a,b;
int c;
a=b/c;

That's what I mean.

Bill

It is valid syntax, but the values of a, b, and c are all undefined
because you did not initialize them. However, no precision was lost.

- --
- --Falcon Darkstar Kirtaran
- --
- --OpenPGP: (7902:4457) 9282:A431

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJIjmxKAAoJEKmxP9YxEE4r+oQQALNdgzDCMoLggffki20TK/Cs
Rcypg1kfLeO4FgL0HBS5+zPm/LGK66tD3UjDcnHygJgdfCBrOdr7PRZ5miTFfyaE
dwD3leGaDqWWREY7ytnQhLhCq+osTnLGaoMnOhVhKAXgLDNomSWht2MO+I+I891l
1TrRB5N0JJ6zx+ED1mfK7CX9i07bd3lLI5zL9G2roetKHyGM3Mkelo7A6t+EKhyn
d146XGOk44KUsY26mCP7ZOUUCd3qh2QIe9S/t7jskQYoTvqWABA/M2aQSoJOt/UK
3tvyCVAU3WjLlS25unJIDx51SFXt6Mob8R56MNnZweZjZesjtXp4DdIBR2q+xMz3
DGzrVzBtkoW1/g2gDdw3gg/6/SzlF2qiaVP8JNwh6Wbq75OXloBMNvZHhVRzLdyM
w0x+lIGkfreTgQNSU4sH6p4ungQKcAdvMupCAbjH/ZyMz+giMg2dZq7AS981syHu
QQTxmiioqvLM5+24O0B4/Zhk2MM6Zvvlzg9CNe8NVwcIMCo9HbKVS0bzLTMUE/+l
USb/8bWPT0TVO228MVIUUl8Vh+11XuR+aYD6RkVjcUrc4kKMFAimG5/ZT+KQ9h4g
QCwplxdKfN5Xhp5RuKtxdhiTjsf9yZBFVRSjPZvW3uT/DJ4OpBnY/kmgq2YD/9Wr
LFzwzMX2Kcd85Y2Jvx+A
=ApH+
-----END PGP SIGNATURE-----
 
O

Old Wolf

Bill Cunningham wrote:
y=x;z=y/count; <-----
x=strtod(argv[1],NULL);
Ah!
The computer can't guess you wanted this line before the one
you marked. Computers are very literal machines. They do
exactly what we tell them to, even if it makes no sense: the trick
is to tell them to do stuff in the right order.

I seem to remember reading somewhere, probably in a discussion
of teaching beginning programming, that some beginners mentally
associate the assignment operator with the mathematical notion
of equality [1], and think that once one has written "y=x",
changes in x will propagate to y, which doesn't happen [2].
Could this be the problem here?

There are actually languages where writing 'y=x'
means that 'y' always has the value that 'x' does.
C is not one of those languages. (Those languages
are usually called 'functional' ones). Assuming
the original poster isn't a troll, then this could
very well be his mental process.
 
B

blmblm

Bill Cunningham wrote:

y=x;z=y/count; <-----
x=strtod(argv[1],NULL);

[ snip ]
I seem to remember reading somewhere, probably in a discussion
of teaching beginning programming, that some beginners mentally
associate the assignment operator with the mathematical notion
of equality [1], and think that once one has written "y=x",
changes in x will propagate to y, which doesn't happen [2].
Could this be the problem here?

There are actually languages where writing 'y=x'
means that 'y' always has the value that 'x' does.
C is not one of those languages. (Those languages
are usually called 'functional' ones).

Good catch. I wasn't thinking about languages outside the
procedural/OO paradigm, but perhaps I should have been.
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top