By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,490 Members | 1,398 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,490 IT Pros & Developers. It's quick & easy.

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

P: 1
Expand|Select|Wrap|Line Numbers
  1. #include<conio.h>
  2. #include<iostream>
  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;
  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;
  35. endA= SecondManf+FourthManf;
  36. cout <<"The end result for the second and the fourth manufacturer is "  <<endA <<endl;
  41. getch();
  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
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 8,916
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

Expert 100+
P: 983
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

Post your reply

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