Struct help

I am having several issues with my program It's giving me syntax errors. Can someone shed light as to why this is? I'm fairly new to this so sorry if I'm not direct enough with my questions.

Syntax error 1:
1
2
3
52 11      Error 'radius' was not declared in this scope
59 4        Error 'diam' was not declared in this scope
59 11      Error 'c' was not declared in this scope


My code is:
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
#include<iostream>
#include <cstdlib>
#include<string>
#include <iomanip>

using namespace std;

struct Circle
{
  int radius;
  string color;
};

int main()
{
   void displayArea(Circle);
   void displayDiameter(Circle);
   
   Circle aRedCircle, aGreenCircle;
   
   aRedCircle.radius = 29;
   aRedCircle.color = "red";
   
   aGreenCircle.radius = 7;
   aGreenCircle.color = "green";
   
   cout << fixed << showpoint << setprecision(2);
   
   displayArea(aRedCircle);
   displayDiameter(aRedCircle);
   
   displayArea(aGreenCircle);
   displayDiameter(aGreenCircle);
   
   system("Pause");
   return 0;
}

void displayArea(Circle c)
{
   double area;
   const double PI = 3.14159;
   area = radius * radius * PI;
   cout << "The " << c.color << " circle with radius " << 
      c.radius <<  "has an area of " << area << endl;
}
void displayDiameter(Circle)
{
   int diameter;
   diam = c.radius * 2;
   cout << "The " << c.color << " circle with radius " << 
      c.radius << " has a diameter of " << diameter << endl << endl;
}
Last edited on
I fixed the diam error. Now I just get the first and third error
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
#include<iostream>
#include <cstdlib>
#include<string>
#include <iomanip>

using namespace std;

struct Circle
{
  int radius;
  string color;
};


void displayArea(Circle c);         
void displayDiameter(Circle c);


int main()              //int main
{
    
   Circle aRedCircle, aGreenCircle;
   
   aRedCircle.radius = 29;
   aRedCircle.color = "red";
   
   aGreenCircle.radius = 7;
   aGreenCircle.color = "green";
   
   cout << fixed << showpoint << setprecision(2);
   
   displayArea(aRedCircle);
   displayDiameter(aRedCircle);  //missing ;
   
   displayArea(aGreenCircle);
   displayDiameter(aGreenCircle);   //diameter not diamater
   
   system("Pause");
   return 0;
}


void displayArea(Circle c)
{
   double area;
   const double PI = 3.14159;
   area = c.radius * c.radius * PI;                     //c.radius
   cout << "The " << c.color << " circle with radius " << 
      c.radius << " has an area of " << area << endl;   //missing "
}
void displayDiameter(Circle c)
{
   int diameter;
   diameter = c.radius * 2;                 //diameter not diam
   cout << "The " << c.color << " circle with radius " << 
      c.radius << " has a diameter of " << diameter << endl << endl;
} 
Line 43: Didn't you mean c.radius ?

Line 47: You need an object name.
 
void displayDiameter(Circle c)

Thank you so much for this. I was trying to figure it out. Yeah It makes sense now that you gave me that information.
Topic archived. No new replies allowed.