Hi guys,
I'm a complete beginner to programming and have been trying to learn c++ through online tutorials. It's a hobby for me and it has been quite fun learning it. I have been attempting to solve one of the problems that was part of a tutorial, but now I find myself unable to understand why my code won't work.
Here's what I'm trying to achieve:
-Write a function called IsEven() that returns true if an integer passed to it is even. Use the modulus operator to test whether the integer parameter is even.
I know there are probably a million ways to do this, and I'd appreciate if anyone would like to suggest simpler solutions. I'd however really like to know why my code won't work. This code will build a solution fine, but it won't give me the answer I'm looking for.
Any help and advice will be greatly appreciated.Code:#include "stdafx.h" #include <iostream> int nValue; bool IsEven () { using namespace std; if (nValue %2 ==0) return true; else return false; } int main () { using namespace std; cout << "Enter an integer" << endl; int nValue; cin >> nValue; IsEven (); return 0; }
Cheers.



2Likes
LinkBack URL
About LinkBacks




