-4

Here are the errors on the following code after the VS2022(v143) upgrade: enter image description here Could someone please suggest what is wrong here and how to fix it?

//Cricle properties problem
#include <iostream>
using namespace std;
float Qradius(float diameter)
{
    float radius = diameter / 2;
    return radius;
}

float Warea(float radius)
{
    float area = (radius *radius) *3.14;
    return area;
}

float Ecircumference(float diameter)
{
    float circumference = 3.14 * diameter;
    return circumference;
}

float Rarclength(float arcangle, float circumference)
{
    float arclength = (circumference *arcangle) / 360;
    return arclength;
}

int main()
{
    float diameter, arcangle;
    float area, circumference, arclength, radius;
    cout << "Type the diameter ";
    cin >> diameter;

    cout << "Type the arcangle ";
    cin >> arcangle;

    cout << "The radius of the circle is " << Qradius(diameter) << endl;
    cout << "The area is " << Warea(radius) << endl;
    cout << "The circumference is " << Ecircumference(diameter) << endl;
    cout << "The arc length is " << Rarclength(arcangle, circumference) << endl;
}
kiner_shah
  • 3,939
  • 7
  • 23
  • 37
skoironiys
  • 16
  • 1
  • Please don't post images of errors, copy them as text into the question. Also, please format your code. Everything left aligned is impossible to read. – ChrisMM Sep 16 '22 at 10:53
  • Click on the warnings and it will tell you the lines were the problem is. All of them are very trivial and should help you to find the problems in your code, because it is also not working as you expect it. E.g. the first one, you never set any value to the variable `radius` – RoQuOTriX Sep 16 '22 at 10:55
  • These seem to be warning and not errors. – kiner_shah Sep 16 '22 at 10:55
  • `Warea(radius)` is UB. See dupe: [Calling function with variable that is being initialized](https://stackoverflow.com/questions/73643920/calling-function-with-variable-that-is-being-initialized/73643982#73643982) – Jason Sep 16 '22 at 10:56
  • you take user input for some variables but not all – 463035818_is_not_an_ai Sep 16 '22 at 10:58
  • 1
    You need code like this `radius = Qradius(diameter);` then `cout << "The radius of the circle is " << radius << endl;` and `cout << "The area is " << Warea(radius) << endl;` – john Sep 16 '22 at 10:59

1 Answers1

2

I solved the warnings and explained why they were coming up in the comments in the code. Also do not use using namespace std;

#include <iostream>

float Qradius(float diameter)
{
    float radius = diameter / 2;
    return radius;
}

float Warea(float radius)
{
    // if no f is specified, the compiler assumes it is a double
    // the warning tells you that it converts a double to float
    // which could lead to loss of data (C4244)
    float area = (radius *radius) * 3.14f;
    return area;
}

float Ecircumference(float diameter)
{
    // same as aboth
    float circumference = 3.14f * diameter;
    return circumference;
}

float Rarclength(float arcangle, float circumference)
{
    float arclength = (circumference *arcangle) / 360;
    return arclength;
}

int main()
{
    float diameter, arcangle;
    // area and arclength are unused (C4101)
    float /*area,*/ circumference, /*arclength,*/ radius;
    std::cout << "Type the diameter ";
    std::cin >> diameter;

    std::cout << "Type the arcangle ";
    std::cin >> arcangle;

    // radius and circumference is never set
    // and later used without setting any value (C6001)
    radius = Qradius(diameter);
    circumference = Ecircumference(diameter);

    std::cout << "The radius of the circle is " << radius << std::endl;
    std::cout << "The area is " << Warea(radius) << std::endl;
    std::cout << "The circumference is " << circumference << std::endl;
    std::cout << "The arc length is " << Rarclength(arcangle, circumference) << std::endl;
}
RoQuOTriX
  • 2,871
  • 14
  • 25