Solved what's wrong wit ma code?

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

11100001111011100111

Newbie
Full Member
Mar 5, 2017
28
72
1
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 "header.h"
#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];

	//determine your fraction structures here
	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
		storeSum1 = equationArr[2] % primeNum;
		storeSum2 = equationArr[5] % primeNum;

		//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
			arrayStorage[arrayFiller] = primeNum;
			//increment for making more room appending in array
			++arrayFiller;
			//dividing the denominators and storing the value inside a variable for later comparison
			storeOrigin3 = equationArr[2] / primeNum;
			storeOrigin4 = equationArr[5] / primeNum;
			//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
			if (storeOrigin3 < primeNum && storeOrigin4 < primeNum) {
				//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 {
				primeNum = 2;
				++loop;
			}
		}
		else {
			if (storeOrigin3 < primeNum && storeOrigin4 < primeNum) {
				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 {
				++primeNum;
				++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
Mar 5, 2017
28
72
1
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

headass
Escobar Tier VIP
Trump Tier Donator
Jun 25, 2014
2,298
37,938
269
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
Jul 21, 2016
246
2,678
13
I'm not a CPP expert but I think something is wrong! I hope it helped.
 
Attention! Before you post:

Read the How to Ask Questions Guide
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
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods