I have a line of string = VOLTAGE 0.231023459 CURRENT -0.234334567 0.345511234 How can I extract the negative fractions from the above line. For positive values I can #define the index of the string and start parsing it.But there is no fixed sign for the values, the values can be...

I have a method that is converting a decimal (double value) into a fraction and putting the numerator and denominator values into an int[] of size 2. Testing it works out fine for most values except when I hit 0.0001. Then the return value is 1.0/1.0. The method: private static...

I have a project for a class where you have to recieve two fractions from a user with different denominators, add them together and output them with the lowest common denominator. Since we have to use principles from only chapters we have covered I cannot make a fraction class so...

Let's say I have a string (like a fraction); var num = "1/2"; Why does this work: var y = num.split(' '); if (y.length > 1) { var z = y[1].split('/'); var a = (+y[0] + (z[0] / z[1])); num = a; } else { z = y[0].split('/'); if (z.length...

I have been searching all over and could not find the answer to this. Basically imagine having a class like so in the header. class fractions { private: int numerator; int denominator; public: //etc etc }; Now I am in the main and want to access the denominator and numerator...

I'm trying to print the output of the function after my values are sent to the function. The cout statement needs a string but I'm not sure how I can return a string from my reduce_fraction function while keeping the math correct. In my add_fraction function, you'll see that I...

This question already has an answer here: Best way to represent a fraction in Java? 24 answers What would the syntax be to make a fraction, for example if I wanted to make a program that takes a fraction and adds it to another fraction. I am talking about...

The following code is working as expected, however I'm unable to display the output on a single line. All numbers are random numbers printed using Random() function. As of now, it's printing like this: 38 --- + 45 90 --- + 16 29 --- + 21 54 --- + 99...

I am new in C++ and I have a problem with operator overloading. I just implemented the functions in header file.I want to add two fractional numbers simplest form to each other.I implemented a gcd for simplification and implemented operator + for addinf the together bu I got an error...

I have the following class which I am trying to use to perform calculations between fractions however every now and again i get a division by zero exception from on the simplify function and i cannot work out why it is doing it public class Fraction { private int top;...