Solved

(12 / 4 * 5 / 2) = 7 ??

Posted on 2000-04-01
2
167 Views
Last Modified: 2010-04-02
Why does (12 / 4 * 5 / 2) = 7 in C++ ? Does it round? Even if I declare it as a double...

-Dan
0
Comment
Question by:SuperMario
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 10 total points
ID: 2676363
This is because you're using plain integer constants...

Try

(12.0 / 4.0 * 5.0 / 2.0)

and you should receive the expected result.
0
 
LVL 3

Author Comment

by:SuperMario
ID: 2676372
Oh... *smacks forehead* Thank you so much for enlightening me!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Focus not getting shifted out of  editbox 2 62
ASP.net build a IF/Then Walkthrough Guide 1 209
White board coding practice 3 86
Which Linux flavors will this run on? 6 87
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall‚Ķ
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now