473,666 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

i got this error: error C2297: '%' : illegal, right operand has type 'double'

1 New Member
Expand|Select|Wrap|Line Numbers
  1. #include<conio.h>
  2. #include<iostream>
  3.  
  4. using namespace std;
  5. int main() 
  6. {
  7. double ManfCode,ProdCode;
  8. int Checkdigit, SecondManf, FourthManf;
  9. int FirstProd,ThirdProd,FifthProd;
  10. int SecondProd,ForthProd;
  11. int FirstManf,ThirdManf,FifthManf;
  12. int endA, endB, endC, endD, endE, endF, endG;
  13. int assist1=0,assist2=0,assist3=0;
  14.  
  15. cout<<"Please enter the Manufacturer Code below"<<endl; 
  16. cin>>ManfCode;
  17. if((ManfCode > 99999)||(ManfCode<10000)) {cout<<"Error, Re-Enter the Manufacturer Code"<<endl; 
  18. cin>>ManfCode;}
  19. cout<<"Please enter the Product Code below"<<endl; 
  20. cin>>ProdCode;
  21. if((ProdCode > 99999)||(ProdCode<10000)) {cout<<"Error, Re-enter the Product Code"<<endl; 
  22. cin>>ProdCode;} 
  23. cout<<"Please enter the Check Digit below"<<endl; 
  24. cin>>Checkdigit;
  25. if((Checkdigit > 9)||(Checkdigit<0)) {cout<<"Error, Re-enter the Check Digit"<<endl; 
  26. cin>>Checkdigit;}
  27. cout <<"The UPC code you entered is \n"<< "0 "<<ManfCode<<" "<<ProdCode<<" "<<Checkdigit<<endl; 
  28. assist1= 10000% ManfCode;
  29. SecondManf= static_cast<int>(assist1/1000);
  30. cout <<"The second number for the manufacturer is "  <<SecondManf<<endl;
  31. assist2= (int)ManfCode % 100;
  32. FourthManf= static_cast<int>(assist2/10);
  33. cout <<"The fourth number for the manufacturer is "  <<FourthManf<<endl;
  34.  
  35. endA= SecondManf+FourthManf;
  36. cout <<"The end result for the second and the fourth manufacturer is "  <<endA <<endl;
  37.  
  38.  
  39.  
  40.  
  41. getch();
  42.  
  43. return 0; 
  44. }
Its just the beginning
Thats my code for Validating A UPC Code
How do i eliminate the error?

I got this error: error C2297: '%' : illegal, right operand has type 'double'
Sep 8 '10 #1
2 7150
Banfa
9,065 Recognized Expert Moderator Expert
Don't use % on variables on type double, it only works on the integer types (char, short, int, long, long long).

Does the manufactures code really have to have type double? Normally codes like that are integers, or rather a string of digits representable as an integer.
Sep 8 '10 #2
Oralloy
988 Recognized Expert Contributor
Since you don't tell us which line your problme occurred on, I'll assume its line 28, where you take 10,000 modulo ManfCode.

I'd ask why lines 28 and 31 read differently. I infer that you're pulling a particular digit out of the code, or is there some other magic going on? If not, I think line 28 should be updated to read
Expand|Select|Wrap|Line Numbers
  1. assist1= (long)ManfCode % 10000;
Please, next time you post remember to use code tags and note the exact line where the error occurred. We're not mind readers.
Sep 8 '10 #3

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

Similar topics

3
11554
by: Martin Koekenberg | last post by:
Hello, Ik get the following error when I install a new Python software package such as Zope or PIL. This is what I get whem I 'make' Zope : running build_ext Traceback (most recent call last): File "/usr/local/zope/Zope-2.7.2-0/setup.py", line 1091, in ?
3
9683
by: Rakesh | last post by:
In my Python code fragment, I want to write a code fragment such that the minimum element of a tuple is subtracted from all the elements of a given tuple. When I execute the following python script I get the following interpreter error.
2
4403
by: Tim Mierzejewski | last post by:
You guys were so great with answering my first question that I've decided to ask you yet again! Again, only the relevant code is included. typedef unsigned int unint; #include <iostream> class Creature { public: unint ReturnSpellPoints() {return crSpellPoints;}
4
4031
by: Ondrej Spanel | last post by:
The code below does not compile with .NET 2003, I get folowing error: w:\c\Pokusy\delegTemplArg\delegTemplArg.cpp(11) : error C2993: 'float' : illegal type for non-type template parameter 'x' The error shows compiler is quite confused - x is not a template parameter at all. I have found two workarounds, but still I think the code should compile.
6
13566
by: BlueTrin | last post by:
Hello I was adapting a C version of SolvOpt in C++ to use it within a virtual class. However I am stuck with the overriding of evaluation and gradiant functions. cStepCurveEvaluator.cpp cStepCurveEvaluator.cpp(14) : error C2296: '.*' : illegal, left operand
2
2119
by: duraisridhar | last post by:
Hi all, While I try to find the modulus on double data , Compiler throws following error "Test.cpp(180): error C2296: '%' : illegal, left operand has type 'double' " Any work around to over come this compiler error .
2
6623
by: dobbouk | last post by:
I'm getting these 2 errors and haven't got a clue whats causing them please java 43: illegal start of type for (i=0;i< Number_of_squares; i++) java 215 identifier expected } heres the whole code
3
2393
by: su817200 | last post by:
Dear Friend, I got the following build error error C2297: '*' : illegal, right operand has type 'unsigned long *' register unsigned char *outof; register unsigned long *into; *into |= (*outof++ & 0xffL) << 16;
1
12851
by: Terry Archer | last post by:
error C2296: '%' : illegal,left operand has type 'double' #include <iostream> #include <fstream> #include <iomanip> using namespace std; const int OUNCES_PER_POUND = 16; const double POUNDS_PER_KILOGRAM = 2.2;
0
8448
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
8871
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
8783
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...
1
8552
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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...
1
2773
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
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.