473,735 Members | 2,327 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error: invalid operands of types `double' and `double' to binary `operator%'

1 New Member
I am trying to reduce fractions.
If I replace double by int,there is no error,and it will run answers. But the wrong one.....
I don't know if I use the reducing fractions' rule wrongly.
Can someone help me pleaseQQ
Expand|Select|Wrap|Line Numbers
  1. RationalNumber::RationalNumber(double a,double b)
  2. {
  3.     if(b>0)//prvent deno<0
  4.     {
  5.         double r;
  6.         if(a<0)//if nume<0
  7.         {
  8.             a=-a;
  9.             r=(a%b);
  10.             while(r!=0)
  11.             {
  12.                 a=b;
  13.                 b=r;
  14.                 r=a%b;
  15.             }
  16.             this->nume=-a;
  17.             this->deno=b;
  18.             cout<<"test2"<<nume<<"/"<<deno<<endl;
  19.         }
  20.         else
  21.         {
  22.             r=a%b;
  23.             while(r!=0)
  24.             {
  25.                 a=b;
  26.                 b=r;
  27.                 r=a%b;
  28.             }
  29.  
  30.             this->nume=a;
  31.             this->deno=b;
  32.             cout<<"test2"<<nume<<"/"<<deno<<endl;
  33.         }
  34.     }
  35.     else
  36.     {
  37.         cout<<"It's a invalid fraction."<<endl;
  38.         cout<<"The fraction will be set to 0/1"<<endl;
  39.         this->nume=0;
  40.         this->deno=1;
  41.         cout<<"test2"<<nume<<"/"<<deno<<endl;
  42.     }
  43. }
  44.  
  45.  
May 15 '15 #1
3 5185
weaknessforcats
9,208 Recognized Expert Moderator Expert
The modulus operator % applies only to integers.

In set theory, the modulo 5 set contains only 0,1,2,3,4. So if you have an element of another set, say the base 10 integer number system, like 17, you convert to modulo five by 17 % 5 which produces 2. That 2 is the element value in the modulo 5 set.

Floating point, on the other hand, has no conversion to modulo 5 because the values of floating point are not defined. That is, 123.456..... has decimal places that go on forever. It can't be pinned down to a fixed value. Hence, no modulus conversion.
May 15 '15 #2
donbock
2,426 Recognized Expert Top Contributor
From a mathematics point of view, a rational number is defined as the ratio of two integers. I don't know what you get from the ratio of two real numbers.
May 16 '15 #3
Zacariaz
9 New Member
it should also be noted that those =-a statements could potentially, though not likely, cause trouble. =(-a) would probably better, or at the very least some spacing.
Jun 16 '15 #4

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

Similar topics

12
9887
by: Sydex | last post by:
When I compile code I get error C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double (double)' to 'double (__cdecl *)(double)' in this part : double Integration::quad2d(double (*func)(double,double)) { nfunc = func ; return qgaus(f1,x1,x2);//error there
0
3697
by: Frank King | last post by:
Hi, I am using CArray and quick sort funciton to sort an array of double type of data points. I found an article in MSDN HOWTO: Quick Sorting Using MFC CArray-Derived Classes ID: Q216858 The article works well with CStringArray. But when I wrote the following code about double type. It does not work for
4
31386
by: muthu | last post by:
In the following code it gives the error "error: invalid operands to binary &" Why it is happening #include <signal.h> #include <errno.h> #define SIGBAD(signo) ((signo) <= 0 || (signo) >= NSIG) /* <signal.husually defines NSIG to include signal number 0 */
2
29701
by: xelloss | last post by:
#include<cstdlib> #include<iostream> #include<iomanip> #include<vector> #include<fstream> using namespace std; double sum(vector<double> x) { double total = 0.0;
2
5116
by: clintonb | last post by:
Victor said: The double value that I'm trying to convert to GCSMoney (which is implemented as cents) was produced by multiplying a dollar amount by an interest rate to get interest. double amount = 126.60; double interestRate = .075; double interest = amount * interestRate;
2
5799
by: Genro | last post by:
#include<stdio.h> #include<TX/graphics.h> #include<time.h> // I need help! struct Krug{ double _x; double _y; double _skox; double _skoy; double _granx1;
2
4992
by: Tyler Palmer | last post by:
I am having a problem with my program. I cant figure out a solution for the compiler error im getting. In function `double endingConversion(double)': invalid operands of types `double ()(double)' and `double' to binary `operator*' Please Help thanks. #include <iostream> #include <iomanip> #include <cmath>
2
13904
by: SunDevil1171 | last post by:
I making a simple single number scrambler/encryptor and as I tried to build the console application the following error occurred: error: invalid operands of types 'void' and 'int' to binary 'operator%' I have no idea what this means. The source code is bellow. #include <iostream> #include <math.h>
0
8958
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8783
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9193
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4821
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3269
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2186
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.