LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   I am just not seeing this error kinda need an extra pair of eyes please (C++) (https://www.linuxquestions.org/questions/programming-9/i-am-just-not-seeing-this-error-kinda-need-an-extra-pair-of-eyes-please-c-708298/)

jus71n742 02-28-2009 08:46 PM

I am just not seeing this error kinda need an extra pair of eyes please (C++)
 
trail.cpp
Code:

#include <cmath>
#include <iostream>
using namespace std;

int find(double, double);

int main(void){

        double num, pos;

        cout << "Please enter a positive integer and the number of";
        cout << "trailing digits:  ";

        cin >> pos >> num;

        find(pos,num);

}

find.cpp
Code:

#include <cmath>
#include <iostream>
using namespace std;

void find(double pos,double num){
        int trail;

        trail = pos % pow(10.0,num);

        cout << endl;
        cout << "The "<<num<<" trailing digits of "<<pos<<" are ";
        cout << trail<<".\n";

}

the error is: Line 19 is just below int main (void) in trail.cpp
Code:

find.cpp: In function ‘void find(double, double)’:
find.cpp:19: error: invalid operands of types ‘double’ and ‘double’ to binary ‘operator%’

I appreciate any help up front

fantas 02-28-2009 08:53 PM

In C/C++ there's no modulo operator defined for floating point values, but you have the option to use functions like fmod.

jus71n742 02-28-2009 09:01 PM

so change doubles to int's and now that I think I really don't need to mod the pow*pow(10, num).
so it should work with
Code:

ans=num%divider ( changing nec variables)

fantas 03-01-2009 04:24 PM

For your basic experiments you'll just be fine with integers. It won't hurt though to also read up on the floating point data types as well. They certainly take a special place and require different handling than integers.


All times are GMT -5. The time now is 07:43 AM.