Esempio n. 1
0
void TenDotFaders::checkForFoos()
{
	if (!hasFoos())
	{
		addTen();
	}
}
Esempio n. 2
0
//a recursive subroutine to carry a one. this is only called when tmp (in sum method) is >= 10)
//it recursively walks through the number until it finds a digit which adds to ten but is not greater than 9
char * addTen(char *charArr, int j, int tmp) {
	if (toInt(charArr[j - 1] + 1) >= 10) {
		//if the digit BEFORE the digit that was called also adds up to or greater than 10
		charArr[j] = toChar(tmp % 10);
		//set the current digit to mod 10 so that we get rid of the 1
		tmp = toInt(charArr[j - 1] + 1); //tmp is now the digit before this one + 1
		j--; //decrement J 
		addTen(charArr, j, tmp); //recursively do it again 
	} else {
		// if it is not >= 10 all is swell in this world 
		charArr[j - 1] = toChar(toInt(charArr[j - 1] + 1));
		charArr[j] = toChar(tmp % 10);
	}

	return charArr;
}
Esempio n. 3
0
//This is where the fun part is...
char * sum(char *val0, char *val1) {
	int size;
	//getting the sizes of the passed char *str
	//so that we can find the largest one
	//and also because C doesn't have anykind of .length method
	//and sizeof returns the sizeof a pointer 
	//so we have to explicitly keep track of size
	int val0Size = getSize(val0);
	int val1Size = getSize(val1);
	//Makin' sure we've got a big enough array for the whole number.
	if (val0Size > val1Size) {
		size = val0Size;
	} else if (val1Size > val0Size) {
		size = val1Size;
	} else {
		size = val1Size;
	}
	//account for an extra zero at the beginning
	char *numArr = makeArray(val0, size);
	char *valArr = makeArray(val1, size);
	int i = size;
	for (; i >= 0; i--) {
		int numArrTmp = toInt(numArr[i]);
		int valArrTmp = toInt(valArr[i]);
		int tmp = numArrTmp + valArrTmp;
		//if tmp >= 10 we need to carry a 1 
		if (tmp >= 10) {
			numArr = addTen(numArr, i, tmp);
			//otherwise we don't
		} else {
			numArr[i] = toChar(tmp);
		}
	}
	free(valArr);
	return endCalc(numArr);
}
Esempio n. 4
0
// this will call the function until crashes because the Stack doesnt has anymore space.. 
int addTen(int a){
    return addTen(a) + 10;
}