Garmaine Staff asked 2 years ago

How to print multiple Zero after the decimal number when I calculate the floating numbers in C++?

I am Using std::cout<<"MEDIA = "<<std::setprecision(6)<<av; to show 5 digits after decimal number. Actually, I am trying to solve URI 1005 (Average 1) problem.

It's working but it's not working when the calculation result is decimal(like: 5,9,10). Then it's not showing the 5 00000 digits after the decimal number.

This is the code.

#include <iostream>
#include <iomanip>
using namespace std;
int main()
    float A=0;float B=0;

    float av=((A*3.5)+(B*7.5))/11;
    std::cout<<"MEDIA = "<<std::setprecision(6)<<av<<endl;
    return 0;

Here not getting the 10.00000 if I enter both input 10.0.