I have program that wants the user to inter an array and revers it and alos serch for some elements in the array
but I have an error C2679 binary'<<': no operater found which takes a rigth-hand operand of type 'void' ( or there is no acceptable convesion).
and I tryed alot to solve it but it dose not work :(

here is my code,

#include <iostream>
using namespace std;
const int x = 5;
int a[x];
void print();
void revers (int b[x]);
int search(int i);

void main()
{
	
	cout<<"Enter the element of the array: \n";
	
	for (int i = 0 ; i<x;i++)
	{
		cin>>a[i];		
    }
	
	print ();
	cout<<"\n";
	search(a[x]);
	
}

void print ()
{
	
	for (int j=0 ; j<x; j++)
	{
		cout<<a[j];
	}

	cout<<"The array after revers is : " << revers (a) << "\n";

}
void  revers (int b[ ])
{
	int k = 0;
	int l = 0;
	int r = x - 1;
	while (l < r )
	{
		int k = b[l];
		b[l] = b[r];
		b[r] = k;
		l++;
		r--;
	}
	
	
}

int  search(int y)
{
	y = 0;
	int n ;
	cout<<"Enter the number you are looking for : ";
	cin>>n;

	for (int i = 0 ;  i < x ; i++)
	{
		if (a[i] == n)
		
			y += 1;
			
	}
	cout<< y <<" times \n";
	
	return y;
}

Recommended Answers

All 7 Replies

>cout<<"The array after revers is : " << revers (a) << "\n";
What does revers return?

revers don't return anything becaues it's type is 'void'

Exactly. So why are you trying to print the return value if there isn't one?

if I chang the type of the function to 'int' insted of 'void' , What the function returns ?

so the program should:
1.) enter an array
2.) reverse the inputted array
3.) then search for some elements in the array

the question is what do you mean by "search for some elements in the array"?
I got confused on that part.

I mean to find out how many times did the element repeated . But this is not my problem , the problem is in the revers function how can I call it in the print function???

>the problem is in the revers function how can I call it in the print function???
Why would you want to do that? reverse reverses the elements in an array. Presumably the only use for printing the result is to display the resulting array, which you can easily do like so:

cout<<"Before: ";

for (int i = 0; i < x; i++)
    cout<< a[i] <<' ';

revers(a);
cout<<"\nAfter: ";

for (int i = 0; i < x; i++)
    cout<< a[i] <<' ';

cout<<'\n';

To correctly return the array for printing isn't terribly complicated, but it's not going to be a simple one-liner just by adding a suitable return value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.