Getting error of "uses undefined struct" while the structure is identified, need help fixing the code

Viewed 31

so I wrote the whole code for my lab, and it looks solid but when I run it, it gives me errors regarding structure not identified even though it is. I will post my code below. The code should use the structure in functions to calculate parameter and area for 2 different radiuses.

#include <iostream>
using namespace std;



//Functions 
struct CircleStr {
    float radius;
    float perimeter;
    float area;
};

void calculateCirclePerimeterStruct(CircleStr& circle)
{
    float radius = circle.radius;
    circle.area = 3.14159 * radius * radius;
}

void calculateCircleAreaStruct(CircleStr& circle)
{
    float radius = circle.radius;
    circle.perimeter = 3.14159 * 2 * radius;
}



int main()
{

    struct CircleStr circle1;
    struct CircleStr circle2;

    circle1.radius = 15.2;
    circle2.radius = 20.1;

    //Calling Functions

    calculateCirclePerimeterStruct(circle1);
    calculateCircleAreaStruct(circle1);

    calculateCirclePerimeterStruct(circle2);
    calculateCircleAreaStruct(circle2);

    //Output

    cout << "LAB0202 -  - 9/15/2022\n" << "-----------------------------------\n\n";
    cout << "Circle App!\n" << "-----------------------------------\n";
    cout << "RADIUS       PERIMETER       AREA\n" << "-----------------------------------\n" << "Struct\n";

    cout << defaultfloat<< circle1.radius << "           " << ; fixed << circle1.perimeter << "          " << circle1.area << endl;
    cout << defaultfloat<<circle2.radius << "           " << ; fixed << circle2.perimeter << "         " << circle2.area << endl;

}


    
    
    
    
    
    
    }
    
    void calculateCirclePerimeterStruct(CircleStr& circle)
    {
        float radius = circle.radius;
        circle.area = 3.14159 * radius * radius;
    }
    
    void calculateCircleAreaStruct(CircleStr& circle)
    {
        float radius = circle.radius;
        circle.perimeter = 3.14159 * 2 * radius;
    }
    
       

Updated all the caps errors, It still doesnt allow me to run it

1 Answers

I wonder why your "C++ code" contains almost only C code but if I remove double method declarations and "; fixed" - which I don't know and obviously didn't work - it now runs. On the fly, I had no better idea than to use "cin" to keep the console window open after execution...

#include <iostream>
using namespace std;



//Functions 
struct CircleStr {
    float radius;
    float perimeter;
    float area;
};

void calculateCirclePerimeterStruct(CircleStr& circle)
{
    float radius = circle.radius;
    circle.area = 3.14159 * radius * radius;
}

void calculateCircleAreaStruct(CircleStr& circle)
{
    float radius = circle.radius;
    circle.perimeter = 3.14159 * 2 * radius;
}

int main()
{

    struct CircleStr circle1;
    struct CircleStr circle2;

    circle1.radius = 15.2;
    circle2.radius = 20.1;

    //Calling Functions

    calculateCirclePerimeterStruct(circle1);
    calculateCircleAreaStruct(circle1);

    calculateCirclePerimeterStruct(circle2);
    calculateCircleAreaStruct(circle2);

    //Output

    cout << "LAB0202 -  - 9/15/2022\n" << "-----------------------------------\n\n";
    cout << "Circle App!\n" << "-----------------------------------\n";
    cout << "RADIUS       PERIMETER       AREA\n" << "-----------------------------------\n" << "Struct\n";

    cout << defaultfloat << circle1.radius << "           " << circle1.perimeter << "          " << circle1.area << endl;
    cout << defaultfloat << circle2.radius << "           " << circle2.perimeter << "         " << circle2.area << endl;

    int x;
    cin >> x;
}
Related