Solved Need help with enum functions

September 18, 2012 at 19:46:08
Specs: Windows 7
Hey guys I'm trying to figure out how to use enum functions to catch small errors, this is my code below. The one error I seem to be getting is that y is never initialized in the code.

Can someone please point out what I'm doing wrong? Thanks.

#include <iostream>
using namespace std;
enum errCheck{ yes, no };
errCheck test(int);
int main(){
	int x = 5;
	errCheck y;
	test(x);
	if (y == yes){
		cout << "There has been an error!\n";
	} else {
		cout << "There were no errors!\n";
	}
	return 0;
}
errCheck test (int x){
	if (x > 10){
		return yes;
	} else {
		return no;
	}
}


See More: Need help with enum functions

Report •

#1
September 18, 2012 at 19:57:10
✔ Best Answer
The one error I seem to be getting is that y is never initialized in the code.
This is true. I assume you want
errCheck y;
test(x);

to be
errCheck y = test(x);

How To Ask Questions The Smart Way


Report •

#2
September 18, 2012 at 19:59:22
Omg, thanks so much... never done these before I forgot that I have to let y have the return of the function...

Report •
Related Solutions


Ask Question