Indrajit
Indrajit

Reputation: 43

calling a function using defined header in C++

I am relatively new to C++. I am trying to call a function using defined header. I have following 2 files(in addition to enter.h file):

// 1. main.cpp

 #include "enter.h"
 #include<iostream>
 using namespace std;

 int main()
 {
 int intdemo=enter();
 cout << "The result is: " << intdemo<< endl;
}

// 2. enter.cpp

#include <iostream>
   using namespace std;
   int enter()
   {
   int thisisanumber;
     cout<<"Please enter a number: ";
     cin>>thisisanumber;
     return thisisanumber;
   }

I am getting the following error message "void value not ignored as it ought to be". and is pointed to the second line of the main function where value of the variable "intdemo" is assigned

Can anyone suggest how to fix this error? i have searched some of the similar posts here but cannot able to understand the problem. Since i am a beginner, any help would be appreciated.

Upvotes: 0

Views: 35

Answers (1)

OMGtechy
OMGtechy

Reputation: 8250

Your header file probably declares the function enter() to return void (this was confirmed in the comments).

Changing this to match your function definition will solve the problem, as well as an unresolved external error you will most likely be getting as a side effect of this.

Upvotes: 1

Related Questions