Hello MaxGreen,
Let's start with the class:
Your code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class var
{
public:
int maxY(int t[], int n)
{
int max;
for (int i=0; i<n; i++)
{
if(max<t[i]) max=t[i];
}
return max;
}
void insert(char mes[]);{ cout<<mes; cin>>x; }
int returnX();{ return x; }
}
|
Add with proper indentation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class var
{
public:
int maxY(int t[], int n)
{
int max;
for (int i = 0; i < n; i++)
{
if (max < t[i]) max = t[i];
}
return max;
}
void insert(char mes[]); { cout << mes; cin >> x; }
int returnX(); { return x; }
}
|
And with a little rearranging:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
class var
{
public:
int maxY(int t[], int n)
{
int max;
for (int i = 0; i < n; i++)
{
if (max < t[i]) max = t[i];
}
return max;
}
void insert(char mes[]);
{
std::cout << mes; std::cin >> x;
}
int returnX(); { return x; }
}
|
Line 17 is a great forward declaration, but not very good as a function.
Writing lines 17 - 20 this way helps the errors stand out.
Once you make it a function then "x" becomes a problem.
Where is it defined? The function expecting it to be a variable of the class.
Then there is the same problems with line 22.
Line 23 is missing something to make it a proper class.
Two more points. "insert" may be better named as "setX" and "returnX" as "getX". "insert" is a bit misleading as to what it does.
Sometimes it is better to keep the code readable until it is working and then put it into 1 line later. I refer to the "insert" function and the "returnX" function.
I also have to ask if you have to use a "char" array or if you could use a "std::string"?
If you have to use a "char" array then the "insert" function needs changed because you are trying to pass a constant char pointer ,(n.insert(
"Enter n= ");), to a char pointer, "char* mag". And this does not work.
You need to get the class right before you can start working on "main".
Andy