I am working on the code that reads an enum. It seems to point to an address instead
Here is the code

thanks for any help

//////////////////////////////////////////////////////////////////
//contribtor.h
#ifndef	CONTRIBUTOR_H 
#define	CONTRIBUTOR_H
#include <iostream>
#include <string>
using namespace std;
//================================================================
//CONSTANT DEFINITIONS

enum Gender {Male=0, Female, None};

class Contributor
{
friend ostream &operator <<(ostream & Out,Contributor &InContrib);
friend istream &operator >>(istream & In, Contributor &InContrib);

public:	
	Contributor();
	Contributor(string InContrib, double Contribution, Gender Sex, int IDKey);
	Contributor(Contributor &CCContrib);
	~Contributor(){cout<<"Test #1b - This is the Contributor destructor. "<<endl;}

/////Overloaded Operators
	Contributor &operator=(const Contributor & RtSide);
	bool operator <(const Contributor & RtSide);
	bool operator >(const Contributor & RtSide);
 	bool operator ==(const Contributor & RtSide);
	bool operator !=(const Contributor & RtSide);
		
private:
	string InContrib;
	double Contribution;
	Gender Sex;
	int IDKey;
};

#endif
////////////////////////////////////////////////////////////////
//contributor. cpp

#include <iostream>
#include <string>
#include <iomanip>
#include "Contributor.h"
using namespace std;

///c-tor implementation 
Contributor::Contributor()
{	Contribution = 0.0f; 
	Sex = None;
	IDKey = 0; 
	cout<<endl<<"Test #1a - This is the default constructor"<<endl;
}
//copy C-tor

Contributor::Contributor(string InContrib, double Contribution, Gender Sex, int IDKey)
{
	InContrib=InContrib;
	Contribution=Contribution;
	Sex=Sex;
	IDKey=IDKey;
	/*cout<<"The Contributor is "<<InContrib<<endl; 
	cout<<InContrib <<"'s Contribution is "<<Contribution<<endl; 
	cout<<InContrib <<"'s Gender is "<<Sex<<endl;
*/}
Contributor::Contributor(Contributor &CCContrib)
{
	//cout<<endl<<"Test #3 - This is the Copy c-tor"<<endl;
	InContrib = CCContrib.InContrib;
	Contribution= CCContrib.Contribution;
	Sex = CCContrib.Sex;
	IDKey = CCContrib.IDKey;
	cout<<CCContrib<<endl;
}
ostream &operator <<(ostream & Out,Contributor &InContrib)
	{
		//Out<<endl<<"Name of the Contributor? " <<endl;
		Out<<"Name: " <<InContrib.InContrib <<endl;
		Out<<"Contribution: "<<InContrib.Contribution<<endl; 
		Out<<"ID Number: " <<InContrib.IDKey<<endl;
		Out<<"Gender: ";  
			switch (InContrib.Sex)
			{
				case Male: cout<< "Male"; break;
				case Female: cout<< "Female"; break;
				//case default: cout<< "None"; break;
				/*case 1: Out<<" Male ";break; 
				case 2: Out<<" Female "; break;*/
				default: Out<<"None ";break;
     		}
		Out<<endl<<endl<<endl;
		return Out; 
	}
istream &operator >> (istream &In,Contributor &InContrib)
	{

		Gender Sex;
		int IDKey;
		double Contribution;
		int SelSex = 0;//selection of gender
		In.clear();
		In.ignore(In.rdbuf()->in_avail(), '\n'); 
		cout<<"\tEnter Contirbutors Name: ";
		getline(In,InContrib.InContrib); 
		cout<<InContrib<<endl;

		cout<<"\tEnter the amount of "<<InContrib.InContrib<<"'s contribution ";
		In>>InContrib.Contribution; 
		cout<<Contribution<<endl;
		
		cout<<"\tNow Enter an ID# for "<<InContrib.InContrib<<" ";
		In>>InContrib.IDKey;
		cout<<IDKey<<endl;
		
		cout<<"\twhat is "<<InContrib.InContrib<<"'s Gender? "<<endl;
		cout<<"\t1. Male. \n\t2. Female \n\t3. None\n\n";
		In >> SelSex;
			switch(SelSex)
			{
				case 1: InContrib.Sex = Male; break;
				case 2: InContrib.Sex = Female; break;
				case 3: InContrib.Sex = None; break;
			}
		return In;
		cout<<Sex<<endl;
	}
Contributor &Contributor::operator = (const Contributor & RtSide)
{
	if(this != &RtSide)
	{
		InContrib = RtSide.InContrib;
		Contribution = RtSide.Contribution;
		Sex = RtSide.Sex;
		IDKey = RtSide.IDKey;
	}	
	return *this;
}
bool Contributor::operator <(const Contributor & RtSide)
	{
		return (InContrib <RtSide.InContrib); 
	}

bool Contributor::operator >(const Contributor & RtSide)
	{
		return (InContrib <RtSide.InContrib);
	}	

bool Contributor::operator ==(const Contributor & RtSide)
	{
		return ((InContrib == RtSide.InContrib)&&(Contribution==RtSide.Contribution)&&(Sex== RtSide.Sex));
	}
bool Contributor::operator !=(const Contributor & RtSide)
	{
		return((InContrib != RtSide.InContrib)||(Contribution!=RtSide.Contribution)||(Sex != RtSide.Sex));
	}
////////////////////////////////////////////////////////////////////////////////
//main driver

#include <iostream> 
#include <string> 
#include "Contributor.h"

using namespace std;	
//============================================================================
//							FUNCTION PROTOTYPES   
//*****************************************************************************
//                    BEGINNING OF MAIN PROGRAM CODE
//****************************************************************************

int main()
{
//Test 1 and 5
	Contributor myObj1;
//Test 2
	Contributor myObj2("phillip",159.75,None,23);
//Test 3
	Contributor myObj3(myObj2);// this uses the copy c-tor to make myObj3 same as myObj2 
	cout<<endl<<"MyObj4....";
	Contributor myObj4("Hank ",4159.56,None,43);
	cout<<endl<<"MyObj5.... ";
	Contributor myObj5("Peggy",1549.34,Female,24);
	cout<<endl<<"MyObj6....";
	Contributor myObj6("Company one",1459.12,None,22);
//Test 4
	cout<< "Test #4 -  The Assignment of myObj1=myObj3" <<endl; 
	myObj1= myObj3; //now all myObjs are myObj2
	cout<<myObj1;
//Test 6
	cout<<"Test #6 - The >> operator " <<endl<<endl;
	cin >> myObj1;
	cout<<myObj1;
//Test 7 
	cout<<"Test #7 - The < operator " <<endl<<endl;
	cout<<"\tmyOjb5 < myObj6 = "<<boolalpha<<(myObj5<myObj6)<<endl<<endl;
//Test 8 
	cout<<"Test #8 - The > operator "<<endl<<endl;
	cout<<"\tmyObj4 > myObj6 = "<<boolalpha<<(myObj4>myObj6)<<endl<<endl; 
	
//Test 9 
	cout<<"Test #9 - The == Operator\n\n";
	cout<<"\tmyObj1==myObj3 = "<<boolalpha<<(myObj1 == myObj3)<<endl<<endl;
	cout<<"\tmyObj1==myObj6 = "<<boolalpha<<(myObj3 == myObj6)<<endl<<endl;

//Test 10 
	cout<<"Test #10 - The != Operator\n\n";
	cout<<"\tmyObj5==myObj3 = "<<boolalpha<<(myObj5 != myObj3)<<endl<<endl;
	cout<<"\tmyObj1==myObj3 = "<<boolalpha<<(myObj1 != myObj3)<<endl<<endl;

cout <<myObj1;

return 0;
}

What's wrong so far is you not reading the half dozen instances which tell you about code-tags.

Just another typical 1-poster who just wades in without a care in the world and just posts as fast as they can. Doesn't give a crap about how the result looks, just so long as it's on the board....

Our Software Development forum category encompasses topics related to application programming and software design. When posting programming code, encase it in (code), (code=syntax), where 'syntax' is any language found within our Code Snippets section, or (icode), for inline code, bbcode tags. Also, to keep DaniWeb a student-friendly place to learn, don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.

Announcement: Please use BB Code and Inlinecode tags

Read Me: Read This Before Posting

Edited 3 Years Ago by mike_2000_17: Fixed formatting

what do you mean by that. I am just trying to get a hint as to why I cant get my enum to work.

A. Use the tags for code inclusion

[code] some code here

[/code]

B. Format your code for better readability - indenting, whitespace between operators and operands. You're not charged by the byte.

C. Give a clear explanation of what seems to be going wrong, and where!

D. Your title refers to the enum - but that seems to work ok for me. However, you do have a problem using some uninitialized variables, both of which I don't think you need - look at the code below from your input method:

cout << "\tEnter the amount of "<< InContrib.InContrib << "'s contribution ";
In >> InContrib.Contribution;
cout << Contribution << endl;

cout << "\tNow Enter an ID# for " << InContrib.InContrib<<" ";
In >> InContrib.IDKey;
cout << IDKey << endl;

Don't you really mean to display the .Contribution and .IDKey members of InContrib?

thanks VManes . That works.
this is my first post and I was not sure how to post my code. thanks again

This article has been dead for over six months. Start a new discussion instead.