I am working on a program to create a calculator with only addition. I still need subtraction, division, and exponent. I am having trouble with this if anyone could help it would be greatly appreciated.

Printable View

- 05-01-2011cowboyz209Does anyone know how to do exponent with just addition?
I am working on a program to create a calculator with only addition. I still need subtraction, division, and exponent. I am having trouble with this if anyone could help it would be greatly appreciated.

- 05-02-2011DeadPlanet
Multipication with addition is easy enough (which you seem to have gotten already).

Exponent is simply repeated multiplication.

a^2 = a * a

a^3 = a * a * a

Why not simply have a loop to call your multiplication code, while holding the current product?

Fractional exponents and negative exponents may be a little more difficult. - 05-02-2011cowboyz209
do I need a nested loop or just do my multiplication then get that sum and multiply it again

- 05-02-2011DeadPlanetCode:
`while the iterator is less than the exponent`

total = base * total

iterator++

end loop

- 05-02-2011CommonTater
- 05-02-2011cowboyz209
i am trying to do this with using only addition so far i have

insertCode:

for (i = 0; i < num2; i++){

sum = sum + num1;

sum++;

- 05-02-2011mike65535
That's not much. Why is that all you have? You were presented with perfectly useful ideas for implementing such a routine.

Why use cryptic names like*num1*and*num2*- call one*exponent*and the other*base*.

Anyway, what is it supposed to do? Does it work? - 05-02-2011cowboyz209
alright so i have

insertCode:`for(i = 0; i < num1; i++){`

sum = sum + num2;

for(i = 0 ; i < num1 ; i++){

sum = sum + num1;

}

}

- 05-02-2011mike65535
That's a joke, isn't it?

Did you compile it? Do you not see what happens to*i*if you reuse it like that?

Where's your respectful use of my suggestion to use descriptive variable names? - 05-03-2011cowboyz209
its not a joke...just change the names to exponent and base same thing.

insertCode:`for (i = 0; i < exponent ; i++){`

sum = sum + exponent; }

for(i = 0; i < exponent; i++){

sum = sum + base;

)

- 05-03-2011claudiu
How about posting your entire code rather than a snippet that doesn't do anything. The question is does this compile? The answer is clearly a big fat NO.

- 05-03-2011cowboyz209
okay well i was just needing help with the for loop for the exponential function everything else complies right