# leitura de floats

## Recommended Posts

comecei a pouco com o c e estou encalhado num programa que faz com que resolva equacoes do tipo ax2 + bx + c

o meu problema e nao conseguir ler os floats pelo scanf e nao sei como ou resolver isto

```
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
int i;

puts("Im a simple Calculator");
printf("\n1-Forma Resolvente\t2-vertice\n");
scanf("%d",&i);

switch(i){

case 1 :
zeros();
break;

case 2 :
vertice();
break;

default :
break;

}

system("PAUSE");
return 0;
}

int zeros(){

double zerosp, zerosn, delta, zero, i, a, b, c;

printf("\nInsert A:"); scanf("%f",&a); // problema aqui
printf("\nInsert B:"); scanf("%f",&b); // ||
printf("\nInsert C:"); scanf("%f",&c); // ||

delta = ( (b) * (b) )  -4 * (a) * (c);

if( delta < 0 ) {                            /* delta < o  porque ainda
nao dei os imaginarios */
puts("DELTA < 0, sem raizes ");

}

if(delta == 0){

zero = (- (b))/ 2 * (a);

printf("\nzero : %f\n", zero);

}

else{

zerosp = (- (b) + sqrt(delta) )/ 2 * (a);
zerosn = (- (b) - sqrt(delta) )/ 2 * (a);

printf("\nzeros : %f | %f\n", zerosp,zerosn);

}
}

int vertice(){

double x,y,i, delta, a,b,c;

printf("\nInsert A:"); scanf("%f",&a); // problema aqui
printf("\nInsert B:"); scanf("%f",&b); // ||
printf("\nInsert C:"); scanf("%f",&c); // ||

delta = ( (b) * (b) ) -4 * (a) * (c);

x = ( -( (b)/ 2 *(a) ) );
y = ( -( delta/ 4* (a) ) );

printf("\nVertice --> (%f , %f)\n", x,y);

}

int i;

printf("\n1-Forma Resolvente\t2-vertice\n");
scanf("%d",&i);

switch(i){

case 1 :
zeros();
break;

case 2 :
vertice();
break;

default :
break;
}
}
```

##### Share on other sites

Estás a pedir um double.

`scanf("%lf", &a);`

`“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”`

-- Tony Hoare

## Create an account

Register a new account

×

• #### Revista PROGRAMAR

• Wiki
• IRC
×
• Create New...