LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-28-2009, 08:46 PM   #1
jus71n742
Member
 
Registered: Apr 2008
Distribution: Ubuntu 8.04 64bit/ 32bit, FreeBSD 8
Posts: 185

Rep: Reputation: 30
Question 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
 
Old 02-28-2009, 08:53 PM   #2
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
In C/C++ there's no modulo operator defined for floating point values, but you have the option to use functions like fmod.
 
Old 02-28-2009, 09:01 PM   #3
jus71n742
Member
 
Registered: Apr 2008
Distribution: Ubuntu 8.04 64bit/ 32bit, FreeBSD 8
Posts: 185

Original Poster
Rep: Reputation: 30
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)
 
Old 03-01-2009, 04:24 PM   #4
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
i need a second pair of eyes spooge Linux - Networking 1 03-16-2005 06:25 PM
Sendmail, kinda working, kinda borken Sizam Red Hat 1 02-08-2005 12:16 PM
some kinda error machiner Linux - Software 2 08-03-2004 07:26 AM
basic proftp questions - kinda works kinda don't case1984 Linux - Newbie 4 11-06-2003 12:29 AM
AAAARGH! My eyes! My beautiful eyes! briancof Linux - Newbie 3 11-27-2001 06:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration