hi! i need help by creating a program that will divide using loops wihout using any division or multiplication sign. the allowed signs are just addition and subtraction. Thank you! i will post my program if someone replies with this.

You are expected to post the code in the first post, but well.
The algo is pretty simple here - remember those multiplication lessons back in elementary school? For a*b you just make a+a addition b times. Similar with division.

yeah. actually, we also need the multiplication process using addition and i've already got that one. but, i still cannot get the algo for division because a/b is not equal to just a-a, b times..- it's zero. please give me the logic here directly..anyway thanks for helping me.. i hope to receive another reply..tnx:)

For integer division, a/b, you subtract b from a, as along as a>b, counting how many times you did that. The rest is a remainder (a mod b)

float divider( int nDivider ){
	int d = 0;
	int fQuo = 20, fFinal = nDivider - 1;
	while ( d < nDivider + 1 ){
	fFinal = fQuo - fFinal;
	d++;
	}
	return fFinal;
}

This is my sample code.. please help me.. i really don't know what to do.. thank you.

To divide one number by another you could probably pass both numbers, say a and b, to the function with intention of doing a/b. Check if b is zero, because dividing by zero is undefined. Within the function you can declare two numbers, say c and d, with c being how many times you can substract b from a and still have a number zero or more and d being the remainder (eg, 10/3 = 3 with 1 remainder translates to a = 10, b = 3, c = 3, d = 1). This type of division is called integer math and is how C++ implements the / operator for type int. What you display or return is up to you. In C++ the return is just c and d is ignored, but you can display both within the function, return c only, whatever. Using the above variable names the main part of the function could look like:

c = 0
d = a 
while b <= d
  d = d - b
  ++c
display c and d

wow! I've run my program already..thank you for helping me.. :)
you guys are so great!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.