so i got this code, and it works like a charm!
int result = 1;
for (; exp--; )
result *= base;
User Profile
Collapse
-
yes, it certainly does. the only problem is that i'm not too sure how to repeat a loop for a set number of times. i'll try figure it out by going through my textbook though....Leave a comment:
-
i suppose you would take the base value, multiply that by the base value, and then multiply the same number of times there is an exponent
so for 5^6
(5*5)
and multiply that by 5, 5 more times over (since the first time counts as once)...Leave a comment:
-
so if this was done on a paper, i would input the numbers
x ^ y
let's say x=5, and y=6
so 5^6
5*5*5*5*5*5=156 25
very basic, i do completely understand that concept (as though it may not seem that way)
so what i'm trying to do with my code, in plain english:
1. ask user to input a number for the base, and a number for the exponent
2. calculate...Leave a comment:
-
i'm not sure if i understand you completely, as i've been only doing this for a few months, but i'll try express myself the best i can.
basically what i'm trying to do is have the user enter in two numbers, (left and right) and then calculating it like this:
left ^ right
but i can't use pow()
i'm not too sure what you meant by "reading in" though
i'm still at a loss for this assignment really,...Leave a comment:
-
Help with exponents loop, not allowed to use pow() library
so i'm trying to set up this exponents loop, keep in mind this is my first year in computer science so my knowledge of script is somewhat minimal. basically this assignment (or at least part of it) tells us to have the user enter 2 numbers, (left and right) and to output the correct answer using a loop to calculate. my idea was to use to write a script so the number the user inputs for the right side will determine the number of times the loop runs....Last edited by sicarie; Oct 21 '07, 04:30 AM. Reason: Code tags are to the right when creating/replying to a post. Please use them.
No activity results to display
Show More
Leave a comment: