THe stuff at the top was already on there when I went to new project. I also was told that C++ compilers also do C so I have Bloodshed Dec C++ compiler (recommended by my comp sci teacher for next semester)

First let me say, use the pow(double x, double y) function when dealing with powers.

In my opinion, this is bad advice. And it's not just my opinion. Take some code that uses pow(x, 2.0) to a code review in front of people who are savvy with regard to scientific programming and you'll receive *lots* of complaints about that usage. That one bit of bad code may well make your reviewers look over every bit of your code in excruciating detail.

The C family of languages are notoriously weak when it comes to scientific computing, and this is one of those weak spots. Most C compilers doesn't know how to compute small integer powers correctly. Even the weakest Fortran compiler knows to compile x**2 as if it were written as x*x. With C, you have to help the compiler out and write x*x explicitly. Alternatively, write a macro (C) / compile-time template (C++) that will do the translation for you. Only use pow() when the power is a non-integer quantity such as the heat capacity ratio γ.

Agreed. I know the consequences of using pow() for smaller integer values. I was intending to give the OP advice on how to deal with the nth power ( What if the OP wanted the nth power? ) as I'm sure you would not want to write :

THis is my new code yet still doesn't work :( Sorry, first day, I can tell there is no room for error and you have to pay attention to detail. Is there anything else I am doing wrong, I keep reviewing it too the book and see nothing wrong....uggg....Could the first day of coding be an indicator if I will be good at computer science or not? :P

THis is my new code yet still doesn't work :( Sorry, first day, I can tell there is no room for error and you have to pay attention to detail. Is there anything else I am doing wrong, I keep reviewing it too the book and see nothing wrong....uggg....Could the first day of coding be an indicator if I will be good at computer science or not? :P

Almost. You forgot main. The OP showed the code in its entirety in post #4. There's no main.

I had assumed the existence of the int main() beforehand as I would presume the OP could at least do that ( if you look there's a close brace at the end of his code... and return 0; ). I found it more important to fix the actual things which would be causing an error.

Clearly that's not what he intended to do, as he was calculating distance.
Or it could be done in a loop, as below:

Code (Text):

double product = 1.0;
for (i = 0; i < n; ++i)
{
product *= side_1;
}

I know he was calculating the distance. Perhaps the reason I gave was not the most polynomial time efficient method in this particular case, but the answer was still correct.

What I was trying to do, was give a beginner C programmer another tool for his toolkit. A way to not just calculate low powers of a number, but any power he might need later on ( without having to write a for loop every time ).

I know he was calculating the distance. Perhaps the reason I gave was not the most polynomial time efficient method in this particular case, but the answer was still correct.

In the context of scientific programming with any language derived from C, no it's not correct. Suppose you had a list to sort. While bubble sort would give the right answer, it would be incorrect, ever. In scientific programming, powers of ±1/2, ±2, ±3/2, and ±3 predominate. Using pow to calculate those is akin to using bubble sort.

##O(n)## is not very efficient after all.

Correct. An O(n) algorithm to calculate xn where n is a positive integer is exactly akin to bubble sort. Properly done, this is an O(log2 n) calculation using multiplication rather than pow. It only takes 4 multiplies to calculate x16, for example.

In the context of scientific programming with any language derived from C, no it's not correct. Suppose you had a list to sort. While bubble sort would give the right answer, it would be incorrect, ever. In scientific programming, powers of ±1/2, ±2, ±3/2, and ±3 predominate. Using pow to calculate those is akin to using bubble sort.

Correct. An O(n) algorithm to calculate xn where n is a positive integer is exactly akin to bubble sort. Properly done, this is an O(log2 n) calculation using multiplication rather than pow. It only takes 4 multiplies to calculate x16, for example.

How can you expect a day one C programmer to understand a second year data structures course? Of course I understand what you're saying, but the OP surely does not ( yet, given what I've seen in this thread ).