Indicating weither or not a value is an integer or Floating Point Value.

Write your question here.

I'm really not understanding these exercises. I'm trying to learn but my arithmetic is a bit rusty.
These are just two of the exercises i'm trying to do.
1
2
3
4
5

10.0 / 3.0 +5 * 2

12.5 + (2.5 / (6.2 / 3.1))


The 10.0 one I came to 13.3 repeating, but i'm not sure what to do with it from there, or if i'm even doing it correctly. I'm trying hard to learn this on my own but i'm struggling immensely and found myself here. Any help is appreciated, and I understand this is probably the BEGINNING of beginning.
Last edited on
It's hard to say, without seeing the exact wording of the original question, what the intention is.
"Compute the value of each legal expression. Indicate whether the value is an integer or a floating point value. If the expression is not legal, explain why."
an integer is a whole number 5 or 15
a floating point value also includes a fraction of a number 5.3 or 2.79

Care is needed with values such as 5 and 5.0
Though each represents the same quantity, 5 is an integer while 5.0 is floating-point.
Okay so you are having trouble understanding what an int(integer) is and a float is.

Let me explain.

An integer is any hole number such as 1,2,3,4,5,6,7,8,9....and so on...

A float is any number and can hold decimal values such as:
1.0, 1.1, 1.3,2.5,2.35..

When doing mathematical operations with these datatypes such as, int, and float, there are a couple things you must keep in mind...

Consider this:

1
2
3
4
5
int     a = 1;
float  b = 1.5;
int     c = 0;

c = a+b;


1) Integers will drop decimal values.. So variable c from above will equal 2...It will not equal 2.5. .

2) To get 2.5 you must change variable c to a float datatype to accept decimal values.

3) If you wanted to round the above integer to the nearest hole number you would apply this simple formula....
c = (a+b)+0.5;
This may look confusing at first but this is how you would round in your head.


You will run into a datatype that is called a double and that is used quiet often. A double is pretty much the same as float but can hold a greater amount of digits.

Hope this helps...


Last edited on
Don't you mean 2.5?
:facepalm sorry, yes 2.5
Last edited on
Topic archived. No new replies allowed.