# Solvedwhat's wrong wit ma code?

#### 11100001111011100111

##### Newbie
Full Member
staying up and finished this idea that i thought up, the perfect calculator for fractions, but so far idk wtf it's going on... not good with debugging either... i'm off to sleep

C++:
``````#include <iostream>
#include <string>

#define cout std::cout
#define endl std::endl
#define cin std::cin
#define string std::string

//Make a Fraction Calculator with addition and subtraction

auto *enterEquation() {
static int equationArray[6];

cout << "Please enter an equation here" << endl;

//enter in 1st fraction
cout << "\n1st Fraction" << endl;
cout << "enter mix whole number ";
cin >> equationArray[0];
cout << "enter numerator ";
cin >> equationArray[1];
cout << "enter denominator ";
cin >> equationArray[2];

//enter in 2nd fraction
cout << "\n2nd Fraction" << endl;
cout << "enter mix whole number ";
cin >> equationArray[3];
cout << "enter numerator ";
cin >> equationArray[4];
cout << "enter denominator ";;
cin >> equationArray[5];

if (equationArray[0] == 0 && equationArray[3] == 0) {
cout << "\nSo your fractions are " << endl;
cout << "first fraction: " << equationArray[1] << " over " << equationArray[2];
cout << " \nsecond fraction: " << equationArray[4] << " over " << equationArray[5] << endl;
cout << endl;
}
else if (equationArray[0] != 0 && equationArray[3] == 0) {
cout << "\nSo your equation is " << endl;
cout << "first fraction: " << equationArray[0] << " and " << equationArray[1] << " over " << equationArray[2];
cout << " \nsecond fraction: " << equationArray[4] << " over " << equationArray[5] << endl;
cout << endl;
}
else if (equationArray[0] == 0 && equationArray[3] != 0) {
cout << "\nSo your equation is " << endl;
cout << "first fraction: " << equationArray[1] << " over " << equationArray[2];
cout << " \nsecond fraction: " << equationArray[3] << equationArray[4] << " over " << equationArray[5] << endl;
cout << endl;
}
else {
cout << "\nSo your equation is " << endl;
cout << "first fraction: " << equationArray[0] << " and " << equationArray[1] << " over " << equationArray[2];
cout << " \nsecond fraction: " << equationArray[3] << " and " << equationArray[4] << " over " << equationArray[5] << endl;
cout << endl;
}

return equationArray;

}

//OK so the calculations can take many turns here
//If denominators are the same for both fractions, then do simple addition and subtraction without tampering the denominator
//If the denominators are different, then first find the lowest common denominator and convert both fractions with the LCD
//If the equation has a mixed number in it, convert that into a improper fraction then proceed to convert according to LCD

void noMixNum(int equationArr[], int from) {
int numoratorSum;

if (from == 1) {
numoratorSum = equationArr[1] + equationArr[4];
cout << "The answer to your equation = " << numoratorSum << " over " << equationArr[2] << endl;
}
else if (from == 2) {
numoratorSum = equationArr[1] + equationArr[4];
cout << "The answer to your equation = " << numoratorSum << " over " << equationArr[5] << endl;
}
}

void doesEqualZero(int equationArr[], int from) {
int storeSum;

if (from == 1) {
storeSum = equationArr[2] / equationArr[5];
equationArr[5] *= storeSum;

noMixNum(equationArr, 2);
}
else if (from == 2) {
storeSum = equationArr[5] / equationArr[2];
equationArr[2] *= storeSum;

noMixNum(equationArr, 1);
}
}

//Prime starts at 2
//The denominator divided by 2,
//  if possible without any remainder left over, then it will divide the denom by 2
//		then it will check if denom == to 1
//			once it reaches 1, we can stop the process of factorizaiton and *'s all of the prime number stored in our array
//				after *'s them all, the output is the LCD for both denominators
//	if not possible with remainders left over, then it will increase the prime number by ++1
//		then it will repeat the process over again to try and divide evenly into the denominator's number
//			then if not possible, this goes on a loop again increase the prime num++1 and trying to divide evenly again

void primeCal(int equationArr[]) {
int storeSum1, storeSum2, arrayStorage[1];
int storeOrigin1 = equationArr[2], storeOrigin2 = equationArr[5];
int storeOrigin3, storeOrigin4;
int division1, division2;
int primeNum = 2, loop = 1, arrayFiller = 0;

for (int i = 0; i < loop; i++) {
//storing value of 0 or a remainder number

//check to see if both denominators evenly divide with no remainder
if (storeSum1 == 0 && storeSum2 == 0) {
//add 1 more loop just in case
++loop;
//successful denominators evenly divide, put this prime # into account within an array
//increment for making more room appending in array
++arrayFiller;
//dividing the denominators and storing the value inside a variable for later comparison
//here we compare the 2 previous variable if they're smaller than the prime number
//if they are, then we are well past over the intended target packs of prime #'s to store/keep
//here we do a for loop to access the amount of stored prime #'s and *'s them all together and
//restore them in array[0]
for (int j = 1; j < sizeof(arrayStorage); j++) {
arrayStorage[0] *= arrayStorage[j];
}
//then we store the value of the LCD being divided by the original denominator value within our array
division1 = arrayStorage[0] / storeOrigin1;
division2 = arrayStorage[0] / storeOrigin2;
//then we replace the original denominator and numerator of both fractions and *'s it opposite to one another
//according to the value within 'division' variables
equationArr[2] *= division2;
equationArr[1] *= division2;
equationArr[5] *= division1;
equationArr[4] *= division1;
noMixNum(equationArr, 1);
break;
}
else {
++loop;
}
}
else {
for (int j = 1; j < sizeof(arrayStorage); j++) {
arrayStorage[0] *= arrayStorage[j];
}
division1 = arrayStorage[0] / storeOrigin1;
division2 = arrayStorage[0] / storeOrigin2;

equationArr[2] *= division2;
equationArr[1] *= division2;
equationArr[5] *= division1;
equationArr[4] *= division1;
noMixNum(equationArr, 1);
break;
}
else {
++loop;
}
}
}
}

auto calculations(int equationArr[]) {
int divideEvenly;

if (equationArr[0] == 0 && equationArr[3] == 0) {
if (equationArr[2] == equationArr[5]) {
noMixNum(equationArr, 1);
}
else if (equationArr[2] != equationArr[5]) {
divideEvenly = equationArr[2] % equationArr[5];
if (divideEvenly != 0) {
divideEvenly = equationArr[5] % equationArr[2];
if (divideEvenly != 0) {
primeCal(equationArr);
}
else {
doesEqualZero(equationArr, 2);
}
}
else {
doesEqualZero(equationArr, 1);
}
}
}
}

int main()
{
auto equation = enterEquation();
calculations(equation);

system("pause");
};``````

Last edited:

#### 11100001111011100111

##### Newbie
Full Member
Oh lol yea i forgot that much, sorry again i was like up in the morning trying to find the algorithm for prime factorization, i thought i'd rally up what ever i can to get the first set done and jump on here.

The problem is the prime factorization algorithm that i've implemented, it doesn't seem to work (search for the function 'void primeCal' in my code) read it and see whats wrong i guess? lol everything is compile-able, if you copy and paste everything into a new file in your cpp file, but when you try to implement a fraction equation that requests the 'primeCal' func, there is an error which i'm alien to.

to proc the 'primeCal' func, type in no 'whole numbers' for both fractions and type in different 'denominators', but no 0, the 'numerator' can be anything except 0, as long as everything is in 'int', thus return proc's the factorization algorithm....

EDIT = actually just input these in,
first fraction = whole number: 0, numerator: anything, denominator: 18
second fraction = whole number 0, numerator: anything, denominator: 12

error

EDIT2 = nvm i found what the problem was

Last edited:

#### mambda

Escobar Tier VIP
Trump Tier Donator
you cant seriously be dropping like 300 lines of code and telling people "hey find the problem that idk how to describe so no information for you"

#### r4z0r

##### Coder
Meme Tier VIP
I'm not a CPP expert but I think something is wrong! I hope it helped.

Attention! Before you post:

99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

• Fill out the form correctly
• Tell us the game name & coding language