Program "jumping" Variables

0

The program is jumping the variables without at least I put the number I want to use on it. I can only put the first and then jump and it results in zero. I do not know if and error of the Dev-C ++ program or the code.

#include<stdio.h>#include<stdlib.h>#include<math.h>voidmain(){floatbasemaior,basemenor,altura,resultado;printf("entre com a base maior do trapezio: ");
    scanf ("f%", &basemaior);
    printf ("entre com a base menor do trapezio: ");
    scanf ("f%", &basemenor);
    printf ("entre com a altura do trapezio: ");
    resultado=(basemaior+basemenor)*altura / 2;
    printf ("\no calculo da area de um trapezio e: f%", resultado);
    system ("PAUSE");
}
    
asked by anonymous 21.03.2014 / 16:02

2 answers

2

Your code has 3 errors:

  • Instead of void main() , use int main() . Some compilers may not accept the first form. Then it is recommended to use int main() , with int returning it from your program, indicating that the program has been successfully executed, for example.
  • Where f% , correct is %f .
  • A% color is missing for height.
  • It looks like this:

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
        float basemaior, basemenor, altura, resultado;
        printf ("entre com a base maior do trapezio: ");
        scanf ("%f", &basemaior);
        printf ("entre com a base menor do trapezio: ");
        scanf ("%f", &basemenor);
        printf ("entre com a altura do trapezio: ");
        scanf ("%f", &altura);
        resultado=(basemaior+basemenor)*altura / 2;
        printf ("\no calculo da area de um trapezio e: %f\n", resultado);
        system ("pause");
    
        return 0; // por causo do int main
    }
    
        
    21.03.2014 / 16:15
    2

    The problem is that you have changed the position format specifier.

    Instead of f% , change them to %f .

    In addition, to make the calculation correctly, add a scanf to the height:

    scanf ("%f", &altura);
    
        
    21.03.2014 / 16:10