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
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.
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.
do I need a nested loop or just do my multiplication then get that sum and multiply it again
except obviously replace the multiply with whatever you are using to multiply (hopefully a function, as that would make sense).Code:while the iterator is less than the exponent
total = base * total
iterator++
end loop
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++;
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?
alright so i have
insertCode:for(i = 0; i < num1; i++){
sum = sum + num2;
for(i = 0 ; i < num1 ; i++){
sum = sum + num1;
}
}
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?
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;
)
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.
okay well i was just needing help with the for loop for the exponential function everything else complies right