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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mark05
    New Member
    • Sep 2010
    • 1

    #1

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

    Code:
    #include<conio.h>
    #include<iostream>
    
    using namespace std;
    int main() 
    {
    double ManfCode,ProdCode;
    int Checkdigit, SecondManf, FourthManf;
    int FirstProd,ThirdProd,FifthProd;
    int SecondProd,ForthProd;
    int FirstManf,ThirdManf,FifthManf;
    int endA, endB, endC, endD, endE, endF, endG;
    int assist1=0,assist2=0,assist3=0;
    
    cout<<"Please enter the Manufacturer Code below"<<endl; 
    cin>>ManfCode;
    if((ManfCode > 99999)||(ManfCode<10000)) {cout<<"Error, Re-Enter the Manufacturer Code"<<endl; 
    cin>>ManfCode;}
    cout<<"Please enter the Product Code below"<<endl; 
    cin>>ProdCode;
    if((ProdCode > 99999)||(ProdCode<10000)) {cout<<"Error, Re-enter the Product Code"<<endl; 
    cin>>ProdCode;} 
    cout<<"Please enter the Check Digit below"<<endl; 
    cin>>Checkdigit;
    if((Checkdigit > 9)||(Checkdigit<0)) {cout<<"Error, Re-enter the Check Digit"<<endl; 
    cin>>Checkdigit;}
    cout <<"The UPC code you entered is \n"<< "0 "<<ManfCode<<" "<<ProdCode<<" "<<Checkdigit<<endl; 
    assist1= 10000% ManfCode;
    SecondManf= static_cast<int>(assist1/1000);
    cout <<"The second number for the manufacturer is "  <<SecondManf<<endl;
    assist2= (int)ManfCode % 100;
    FourthManf= static_cast<int>(assist2/10);
    cout <<"The fourth number for the manufacturer is "  <<FourthManf<<endl;
    
    endA= SecondManf+FourthManf;
    cout <<"The end result for the second and the fourth manufacturer is "  <<endA <<endl;
    
    
    
    
    getch();
    
    return 0; 
    }
    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'
    Last edited by Frinavale; Sep 8 '10, 08:59 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags and added the error message to the thread.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    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.

    Comment

    • Oralloy
      Recognized Expert Contributor
      • Jun 2010
      • 988

      #3
      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
      Code:
      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.

      Comment

      Working...