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++)
	print ();

void print ()
	for (int j=0 ; j<x; 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;

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

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

Edited by __avd: Added [code] tags. Do wrap your programming code blocks within [code] tags

7 Years
Discussion Span
Last Post by Narue

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] <<' ';

cout<<"\nAfter: ";

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


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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.