I am going back through my textbook to get better and programming and I am getting this code error.
1>c:\documents and settings\acaughg\my documents\visual studio 2008\projects\ch2pe16\ch2pe16\main.cpp(21) : error C2296: '%' : illegal, left operand has type 'double'
1>c:\documents and settings\acaughg\my documents\visual studio 2008\projects\ch2pe16\ch2pe16\main.cpp(23) : error C2296: '%' : illegal, left operand has type 'double'
Here is the program.
#include<iostream>
using namespace std;
int main()
{
double centimeters;
double totalInches;
double yard;
double feet;
double inches;
cout<<"Input length in centimeters: "<<endl;
cin>>centimeters;
cout<<"The total length is "<<yard<<" yard(s), "<<feet<<" feet (foot), and "<<inches<<" inch(es)."<<endl;
system("pause");
}
I know the error is with ->totalInches = totalInches%36; but I dont understand why. I used the same code on another program and the only difference was I was using int data types and now I am using double. Any help would be appreciated.
I don't think you can use the modulus operator with floating points... though I'm new to C++ so that might be incorrect. You could try doing the static_cast<int> for those particular lines.