Need Help in C programing math

Thread Starter

Ralf

Joined Mar 16, 2009
31
normal maths is 4 X 5
but i want it in programming language what will it be?
may i know in C language the multiple is it something like this?

abc = 4 * 5; (of coz this is not my real program)


my program for multiple is this:
analogvoltage1 = result * 1024;
analogvoltage2 = 5000000/analogvoltage1; //forumal to get my analog voltage
result1 = 5000000-analogvoltage2;
result2 = 10000000*analogvoltage2;
resistor = result2/result1; //forumal to get my register value of R4

somehow my all result is wrong.
 
Can you show the circuit or problem that you are trying to solve?

Do you get the correct result in any of the multipication steps that you take? How do you define each of the variables that you use, i.e. analogvoltage1, result, resistor, ..., in the program?
 

Mark44

Joined Nov 26, 2007
628
To continue where StayAtHomeElectronics left off, what are the types of your variables? I suspect that they might be int.

If your declaration for result1 and result2 is something like this:
Rich (BB code):
int result1, result2;
then you will not get the value you probably want in this statement (or in the other statement that involves division):
Rich (BB code):
resistor = result2/result1;
The reason for this is that there are two kinds of division in C: integer division and floating point division. For example 6/2 is 3, which is what you would expect, but 6/4 is 1and 1/2 is 0, both of which are surprising to C neophytes.
 
Top