I’m having an error in my c++ exercise. What can I do to fix it?

Asked

Viewed 25 times

-1

#include <math.h>

#include <iomanip>
#include <iostream>

using namespace std;

int main() {
    float R;
    float pi = 3.14159;
    float volume = (4.0 / 3) * pi * pow(R, 3);
    cin >> R;
    cout << fixed << setprecision(3);
    cout << "VOLUME = " << volume << endl;
}

And that’s my way out.

inserir a descrição da imagem aqui

  • 1

    Maybe you should read the variable R before to use it in the calculations.

1 answer

1

The entrance R is requested afterward to be used in the calculation. You need to change the code for something like

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

using namespace std;

int main() {
    float R;
    float pi = 3.14159;
    float volume;

    cin >> R;
    volume = (4.0 / 3) * pi * pow(R, 3);

    cout << fixed << setprecision(3);
    cout << "VOLUME = " << volume << endl;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.