HI all,

First of all:
I was reading about constant arrays in a book and I didn't really get the idea behind it's use or how it functions though I do understand that the values of the array items is not going to change .. help clarify this issue please ..

Secondly:

I have to do a program but through steps and I try my code after each step

Well I've done two functions one to read the values of salaries and the other is to find the maximum value. However, I have got two error saying :

error C2664: 'read_salary' : cannot convert parameter 1 from 'double [5]' to 'double'
and
error C2664: 'max_salary' : cannot convert parameter 1 from 'double [5]' to 'double'


it's basically the same problem in both errors, I know that it has to do with some assignment of variables or something like that as I have already googled the type of error but have not succeeded to fix the error

this is my code : (note:please help so I can keep moving to build the other parts of my program )

# include <iostream>
using namespace std;

void read_salary(double , int);
int max_salary(double, int);

int main()
{
	int looper;
	int max;
	double salary[5];

	read_salary(salary,looper);
	max_salary(salary, looper);
	cout << "The max" << max;
		
    
return 0;

}

void read_salary(double salary[], int looper)
{
	for (looper=0; looper<5; looper++)
	{
		cout << "Please enter employee #" 
			 << looper <<"'s salary" <<endl; 
		cin >> salary[looper];
	}
}

double max_salary(double salary[], int looper)
{
	int max_index =0;

	for (looper=1; looper<5; looper++)

		if (salary[max_index] < salary[looper] )
		{
			max_index=looper;
		}
	
	 return max_index;
}

Your help is highly appreciated and your explaining is of more value.

Edited 7 Years Ago by new programer: n/a

the prototype definitions that u have declared at the top are wrong as you are passing an array( but in ur case u are only passing a double variable here)

so the prototypes must be....

void read_salary(double[] , int);
int max_salary(double[], int);

try running ur program now....
the errors must be resolved...

HI all,

First of all:
I was reading about constant arrays in a book and I didn't really get the idea behind it's use or how it functions though I do understand that the values of the array items is not going to change .. help clarify this issue please ..

Secondly:

I have to do a program but through steps and I try my code after each step

Well I've done two functions one to read the values of salaries and the other is to find the maximum value. However, I have got two error saying :

error C2664: 'read_salary' : cannot convert parameter 1 from 'double [5]' to 'double'
and
error C2664: 'max_salary' : cannot convert parameter 1 from 'double [5]' to 'double'


it's basically the same problem in both errors, I know that it has to do with some assignment of variables or something like that as I have already googled the type of error but have not succeeded to fix the error

this is my code : (note:please help so I can keep moving to build the other parts of my program )

# include <iostream>
using namespace std;

void read_salary(double , int);
int max_salary(double, int);

int main()
{
	int looper;
	int max;
	double salary[5];

	read_salary(salary,looper);
	max_salary(salary, looper);
	cout << "The max" << max;
		
    
return 0;

}

void read_salary(double salary[], int looper)
{
	for (looper=0; looper<5; looper++)
	{
		cout << "Please enter employee #" 
			 << looper <<"'s salary" <<endl; 
		cin >> salary[looper];
	}
}

double max_salary(double salary[], int looper)
{
	int max_index =0;

	for (looper=1; looper<5; looper++)

		if (salary[max_index] < salary[looper] )
		{
			max_index=looper;
		}
	
	 return max_index;
}

Your help is highly appreciated and your explaining is of more value.

Your prototype :

void read_salary(double , int);
int max_salary(double, int);

Means that they take a double variable and an int variable.

Instead use this :

void read_salary(double Array[], int);
int max_salary(double Array[], int);

It problem is resolved indeed
Thanks a lot

I'll never forget to add the braces next time "hopefully" =)

how about the first part of the query ?

Your prototype :

void read_salary(double , int);
int max_salary(double, int);

Means that they take a double variable and an int variable.

Instead use this :

void read_salary(double Array[], int);
int max_salary(double Array[], int);

yes dear exactly .. error is resolved

This article has been dead for over six months. Start a new discussion instead.