473,888 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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 12901
tdlr
22 New Member
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
6055
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 error message: error C2297: '&' : illegal, right operand has type 'bool (__thiscall cDungeon::*)(int,int)'
3
2487
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 wrong? I am using g++ (GCC) 3.3.5 on a Debian Sarge system. The compiler complains: //**************************** //**************************** Compiler output starts *********** cd /home/red/tmp/testprogs/
72
4291
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 c?
6
17017
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 convert type 'double' to 'bool' The code is
1
1511
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 constructor that looks like this: public CHITextBox () : base() {...} Then in Form1.Designer.cs, I changed the relevant line to: this.CHIMain = new MyRTF.CHITextBox.CHITextBox();
0
1997
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 piece of software developed using VC++ 4.2, running on Windows NT 3.51 to VC++ 2005, running on Windows XP Pro SP2. I went through all of the necessary gyrations to reach the point where all of the deprecated functions were dealt with. I got a...
15
8697
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 getting the error can anyone help me.. i dont knw whr i m doing mistake.. thankx in advance Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
3
6689
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
22431
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 watching a video and tried copying the author's code into bluej and it gives me an error. I apologize in advance if I am not copying it here correctly. class WhileLoop { int counter=0; while (counter<10) { System.out.println...
0
9959
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11176
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10772
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10434
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9593
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5812
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6012
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4638
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.