473,839 Members | 1,380 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 7172
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
11574
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
9695
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
4408
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
4039
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
13595
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
2132
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
6643
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
2402
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
12891
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
9855
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...
1
10649
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,...
0
10295
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
9426
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...
1
7829
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
7018
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
5682
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
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4487
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.