473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

How to resolve "illegal,left operand has type 'double" error?

error C2296: '%' : illegal,left operand has type 'double'

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. const int OUNCES_PER_POUND = 16; 
  7. const double POUNDS_PER_KILOGRAM = 2.2;
  8.  
  9. int main()
  10. {
  11.     int Pounds;
  12.     int Ounces;
  13.     double Kilograms;
  14.     double totalPounds;
  15.     double totalOunces;
  16.  
  17.     ifstream fin;
  18.     ofstream fout;
  19.  
  20.     fin.open("inData.txt");
  21.     fout.open("outData.txt");
  22.  
  23.     fin >> Kilograms;
  24.  
  25.     totalPounds = static_cast<double>(Kilograms * POUNDS_PER_KILOGRAM);
  26.     totalOunces = static_cast<double>(Pounds * OUNCES_PER_POUND);
  27.     Pounds = static_cast<int>(totalOunces / OUNCES_PER_POUND + 0.5);
  28.     Ounces = static_cast<int>(totalPounds % OUNCES_PER_POUND);
  29.  
  30.     fout << Pounds << "\nPounds";
  31.     fout << Ounces << "\nOunces";
  32.     fin.close();
  33.     fout.close();
  34.  
  35. return 0;
  36. }
Feb 2 '11 #1
1 12788
tdlr
22
You cannot use % with double. Change totalPounds to an integer type like long.
Feb 2 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kostatus | last post by:
The following code worked perfectly fine until i modified an unrelated part of the program: this->dungArea.mBlocked = mioS.mio_dungArea.mFlags & isBlocked; after that i started getting the...
3
by: H. S. | last post by:
Hi, I am trying to compile these set of C++ files and trying out class inheritence and function pointers. Can anybody shed some light why my compiler is not compiling them and where I am going...
72
by: Paminu | last post by:
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to something different for the same values of a, b and...
6
by: Doug | last post by:
Hi I have a short piece of trial code that compares some input and then produces a message based on the value. However I get a build error that i dont know how to resolve ' Cannot implicitly...
1
by: Dom | last post by:
This one is a little difficult to explain. I placed a RichTextBox control on my form, I called it chiMain, then I wrote CHITextBox.cs. This class extends the RichTextbox class, and has a...
0
by: =?Utf-8?B?UGF1bCBIYWdlcg==?= | last post by:
I've been trying to solve this issue for the better part of a month. My attempts to get an answer on the MSDN groups proved to no avail. Here is the situation/problem. I am migrating an old...
15
by: squrel | last post by:
Hello All.. I m having some problem here.. i m using VB6 and SQLServer 2000... i m getting this error " statement invalid outside type block" i m sending u the code and the bold line is where i m...
3
by: hmznzr | last post by:
when a user inputs a value into a text box, i am searching that value in my dataset. although the number that i entered is in my dataset, i am getting this excemption. please help me
2
by: Christina Arena | last post by:
I'm just starting to learn java as part of a class I am required to take as a math major. I am feeling completely lost. I guess we're supposed to learn this as independently as possible. I was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.