Error

Why Its Not Compiling
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

void square(double);
int main()
{
 double num;
 num = 123.456;
 cout << "\n" << " the square of num is"  <<square(num);
 cout << "\n" << "the current value of num is " << num;

}
void square(double x)
    {
  return x * x;
 }
1
2
3
4
5
6
7
source_file.cpp: In function ‘int main()’:
source_file.cpp:12:43: error: no match foroperator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘void’)
  cout << "\n" << " the square of num is"  <<square(num);

source_file.cpp: In function ‘void square(double)’:
source_file.cpp:19:14: error: return-statement with a value, in function returning 'void' [-fpermissive]
   return x * x;



Check the return type of the square function. If it's returning a double value, the return type can't be void.
Got It Thanks
Topic archived. No new replies allowed.