New to programming, writing a cubic formula calculator, having stupid/newbie issues

New to programming, writing a cubic formula calculator, having stupid/newbie issues

This is a discussion on New to programming, writing a cubic formula calculator, having stupid/newbie issues within the C Programming forums, part of the General Programming Boards category; Hey guys.
Im trying to write a program to calculate the roots of a cubic using Cardanos formula. Im new ...

New to programming, writing a cubic formula calculator, having stupid/newbie issues

Hey guys.

Im trying to write a program to calculate the roots of a cubic using Cardanos formula. Im new to programming and C, i've been at this problem for about 4 hours or so. I struggled to get my head around function prototypes and I dont really think i've worked it out yet.

Firstly, if i omit the A1 = blah line, it compiles, but I get "Q = nan S = nan", i dont understand why its returning "not a number" for these values??

Secondly, i dont understand how to use the pow() operator on the A1 line.

Thirdly, it wont compile because i think i've stuffed up the use of the function. I dont quite understand whats going on.

Fourthly.. should it be int main(), or float main(), the values that are to be calculated could be floating point numbers, not integers.

Fifthly.. I want it all in terms of a = 1, hence my if (a != 1) line, i used an if statement to do this, but then i wasn't sure if i needed an else statement. cant i just remove the else statement? is that redundant? i just want it to test if a is equal to 1, and if it isnt, i want it to divide the other coefficents by a.

By associating with wise people you will become wise yourselfIt's fine to celebrate success but it is more important to heed the lessons of failureWe've got to put a lot of money into changing behavior

I struggled to get my head around function prototypes and I dont really think i've worked it out yet.

You are only asking for unnecessary confusion by focussing on some kind of math problem at the same time as you try to learn how to use (eg) function prototypes. Focus exclusively on writing and testing functions using the most basic elements you can -- eg, pass a number in, multiply by 2, return the number, print it out. Once you are comfortable with that, you can get more complicated with the math or whatever higher purpose you are trying to serve.

Secondly, i dont understand how to use the pow() operator on the A1 line.

pow() is not an operator, and it you don't have one on the A1 line. How would you like to use it?

Thirdly, it wont compile because i think i've stuffed up the use of the function. I dont quite understand whats going on.

When did you stop being able to compile it? You should not write so much without checking to make sure it will compile (this relates to what I said first off). You should write a couple of lines, use some kind of temporary printf() output to test the current state of affairs, then compile and run and keep repeating the process every few lines at this stage.

Anyway, what is the error: "Stuffed up use of function on line 12?"

Fourthly.. should it be int main(), or float main(), the values that are to be calculated could be floating point numbers, not integers.

It should always be int main and never anything else; main() returns an integer to the operating system at the end of the program (possibly indicating the outcome, etc). So it should never return a float or anything other than int. This has more or less nothing to do with the other variables. Make sure you include a return statement at the end of main() and that it does return an int (eg, "return 0" is fine).