What's wrong

I want to get the maximum number from input numbers and get area, bat program doesn't work!can anyone tell me what's the problem

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
#include<iostream>

using namespace std;

class circle
{
public:
	circle();
	void setradius(double r);
	double getradius()
	{
		return radius;
	}
	double getarea();
	void output();
	void input();
	void maximum();
private:
	double radius;
	double area;
	double a[5];
	double b[5];
	double max;
};

int main()
{
	circle shrjan;
	shrjan.input();
	shrjan.maximum();
	
	shrjan.getarea();
	shrjan.output();
	return 0;
}

circle::circle()
{
	for(int i=0;i<=5;i++)
	a[i]=0;
}
void circle::setradius(double r)
{
	radius=r;
}
double circle::getarea()
{
	area=3.14*radius*radius; 
	return area;
}
void circle::output()
{
	cout<<area<<endl;
}

void circle::input()
{
	for(int i=0;i<=5;i++)
	{cin>>a[i];
	for(int j=0;j<=5;j++)
		b[j]=a[i];}
	max=b[0];
}
void circle::maximum()
{ 
	for(int j=0;j<=5;j++)
	{if(b[j]>max) max=b[j];}
	setradius(max);

}
Take a look at lines 60-61. Every time the user inputs a number, you cycle through all the elements of b[] and you
set them all equal to the most recent entry. When all is said and done, you have an entire array full of the exact same number. I'm not sure exactly what you meant to do with that array, but I don't think that's correct.
Last edited on
Topic archived. No new replies allowed.