Jump to content
gramer

leitura de floats

Recommended Posts

gramer

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 :
                  newmenu();
            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 ");
       newmenu();

       }

    if(delta == 0){

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

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

       }

   else{

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

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

        }
   }

   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);
       newmenu();

       }

    int newmenu(){
        int i;

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

switch(i){

          case 1 :
                zeros();
            break;

          case 2 :
                 vertice();
            break;

          default :
                  newmenu();
            break;
          }
        }

Share this post


Link to post
Share on other sites
KTachyon

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.