Jump to content

Price fraction: Difference between revisions

no edit summary
(→‎{{header|Python}}: Bisection library code shown)
No edit summary
Line 130:
.3444635 .5
.0491907 .1
 
=={{header|C}}==
<lang c>#include <stdlib.h>
#include <time.h>
#include <stdio.h>
 
int main()
{
//Just get a random price between 0 and 1
srand(time(NULL));
float price = (float)((int)rand()%101)/100;
float tops=0.06;
float std_val = 0.10;
 
//Conditionals are a little odd here
//"(price-0.001 < tops && price+0.001 > tops)" is to check if they are equal. Stupid C floats, right? :)
while((price>tops || (price-0.001 < tops && price+0.001 > tops)) && tops<=1.01)
{
tops+=0.05;
 
if(std_val < 0.26)
std_val += 0.08;
else if(std_val<0.50)
std_val +=0.06;
else
std_val +=0.04;
 
if(std_val > 0.98)
std_val = 1.0;
}
 
printf("Value: %.2f\nConverted to standard: %.2f\n", price, std_val);
}</lang>
 
=={{header|C sharp|C#}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.