Exercise URI 1012 - Wrong answer 20%



  • I did the exercise, almost all outputs are coming out as the URI output are asking, but the first requirement is not as you ask in the program. I used setprecision, but I am in doubt because the first result does not round 3 decimal places after comma. a 3.0 b. c 5.2

    TRIANGULO: 7.800
    CIRCULO: 84.949
    TRAPEZIO: 18.200
    QUADRADO: 16.000
    RETANGULO: 12.000
    

    my first exit TRIANGULO leaves only 7.8 and the others leave perfectly.

    #include <iostream>
    #include <iomanip>
    #include <math.h>
    

    int main(int argc, char** argv)
    {
    double pi = 3.14159;
    double a, b, c;
    double area_triangulo, area_circulo, area_trapezio,
    area_quadrado,area_retangulo;

    std::cin &gt;&gt; a &gt;&gt; b &gt;&gt; c;
    
    area_triangulo = a * c / 2;
    area_circulo = pi * pow(c, 2);
    area_trapezio = ((a + b)* c)/2;
    area_quadrado = pow(b, 2);
    area_retangulo = a * b;
    
    std::cout &lt;&lt; "TRIANGULO: " &lt;&lt;area_triangulo &lt;&lt; std::setprecision(5)&lt;&lt;           
    std::fixed &lt;&lt; std::endl;    
    std::cout &lt;&lt; "CIRCULO: " &lt;&lt;area_circulo &lt;&lt; std::setprecision(3)&lt;&lt; 
    std::fixed &lt;&lt; std::endl;    
    std::cout &lt;&lt; "TRAPEZIO: " &lt;&lt;area_trapezio &lt;&lt; std::setprecision(3)&lt;&lt; 
    std::fixed &lt;&lt; std::endl;
    std::cout &lt;&lt; "QUADRADO: " &lt;&lt;area_quadrado &lt;&lt; std::setprecision(3)&lt;&lt; 
    std::fixed &lt;&lt; std::endl;
    std::cout &lt;&lt; "RETANGULO: " &lt;&lt;area_retangulo &lt;&lt; std::setprecision(3)&lt;&lt; 
    std::fixed &lt;&lt; std::endl;
    
    return 0;
    

    }



  • O http://www.cplusplus.com/reference/ios/fixed/ indicates that the following writings will be made with fixed point notation. The amount of digits shown after the crankshaft is set with http://www.cplusplus.com/reference/iomanip/setprecision/ .

    If you want to show 3 digits after the wig you must use:

    std::setprecision(3);
    

    You must use std::fixed and set::setprecision before writing any numerical output and only once:

    std::cout << std::fixed << std::setprecision(3);
    std::cout << "TRIANGULO: " <<area_triangulo << std::endl;
    std::cout << "CIRCULO: " <<area_circulo << std::endl;
    std::cout << "TRAPEZIO: " <<area_trapezio << std::endl;
    std::cout << "QUADRADO: " <<area_quadrado << std::endl;
    std::cout << "RETANGULO: " <<area_retangulo << std::endl;
    

    https://ideone.com/P9bEN3


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2