Error: variable has incomplete type void

Hello I'm fresh into c++ and I'm really struggling with this error. I'm tasked to have all the outputs for my values of area, perimeter, and diagonal in a display function. I created one and am trying to invoke the function within my main file but I keep encountering the error in the title.

What exactly does the error mean in this situation and how should I go about fixing it? Thanks in advance.

The display function is being called in int main() on line 43.
The display function was created on line 72.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <iomanip> //using setprecision(1)
#include <math.h>
using namespace std;
 
//functions
double findArea(double sideOne, double sideTwo);
double findPerimeter(double sideOne, double sideTwo);
double findDiagonal(double sideOne, double sideTwo);
void display(double sideOne, double sideTwo, double area, double perimeter, double diagonal);
 
//Main
int main()
{   //Variables
    double sideOne, sideTwo;
 
    //Gathering the number for boths sides from the user
    cout << "Please enter the length of side one." << endl;
    cin >> sideOne;
 
    cout << "\nPlease enter the length of the side two." << endl;
    cin >> sideTwo;
 
    //Validating that the values are greater than zero
    if (sideOne <=0 || sideTwo <= 0)
    {
        cout << "Both values for the length need to be greater than zero." << endl;
        exit(0);
    }
 
    //setting precision to one decimal place
    cout << fixed << setprecision(1);
    // Declaring the variable area and invoking the findArea function to calculate and assign the value
    double area = findArea(sideOne,sideTwo);
 
    //Invoking the perimeter function and outputting value
    double perimeter = findPerimeter(sideOne,sideTwo);
 
    //Invoking diagnal function
    double diagonal = findDiagonal(sideOne,sideTwo);
 
 
    void display(area, perimeter, diagonal);
    {
        cout << area << endl; // this line is just here for testing. Definitely wrong.
    }
    return 0;
}
 
//Calculating Area
double findArea( double sideOne, double sideTwo)
{
    double area = sideOne * sideTwo;
    return area;
}
 
//Calculating Perimeter
double findPerimeter(double sideOne, double sideTwo)
{
    double perimeter = ((sideOne * 2) + (sideTwo * 2));
    return perimeter;
}
 
//Calculating diagnal
double findDiagonal(double sideOne, double sideTwo)
{
    double diagonalTotal = ((sideOne *sideOne) + (sideTwo*sideTwo));
    double diagonal = pow(diagonalTotal,0.5);
    return diagonal;
}
 
void display(double sideOne, double sideTwo, double area, double perimeter, double diagonal)
{
    cout << "The area is: " << area << endl << endl;
    cout << "The perimeter is: " << perimeter << endl<< endl;
    cout << "The diagonal is: " << diagonal << endl;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
int main()
{   //Variables
    double sideOne, sideTwo;
 
    //Gathering the number for boths sides from the user
    cout << "Please enter the length of side one." << endl;
    cin >> sideOne;
 
    cout << "\nPlease enter the length of the side two." << endl;
    cin >> sideTwo;
 
    //Validating that the values are greater than zero
    if (sideOne <=0 || sideTwo <= 0)
    {
        cout << "Both values for the length need to be greater than zero." << endl;
        exit(0);
    }
 
    //setting precision to one decimal place
    cout << fixed << setprecision(1);
    // Declaring the variable area and invoking the findArea function to calculate and assign the value
    double area = findArea(sideOne,sideTwo);
 
    //Invoking the perimeter function and outputting value
    double perimeter = findPerimeter(sideOne,sideTwo);
 
    //Invoking diagnal function
    double diagonal = findDiagonal(sideOne,sideTwo);
 
    /***************** commented out *******************
    void display(area, perimeter, diagonal);
    {
        cout << area << endl; // this line is just here for testing. Definitely wrong.
    }
    *********************************************************/
    display( sideOne, sideTwo, area, perimeter, diagonal ); // *** added

    return 0;
}
Hey thanks so much! I take it when you use a void function you don't need to put void in the main function you just invoke it with the name of the function and parameters it's using?
Yes. Just invoke it, like we invoke the other functions that return values.
Topic archived. No new replies allowed.