I have had this problem many times and I have never been able to get my while loops corrected, hence the reason I never used them, so maybe I need a professional solution to the problem.
I never really got classes on how they worked, although they had some relevance to structure, the public private and protected always confused me, still does in a way, but I was reading on cprogramming.com and well they made it a bit clear but not the whole way. SO to keep my program running I said "hey lets put a while loop in there to see what all my outputs are" boy did I do something wrong with my loops cause it posts the same thing over and over and I dunno how to fix it, here is my cheesy sample:
// class.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <conio.h>
#include <iostream>
using namespace std;
class Gender
{
public:
Gender();
~Gender();
void setGender(int G);
int readGender();
private:
int gender;
};
int _tmain(int argc, _TCHAR* argv[])
{
int s;
Gender being;
cout << "What Gender are you?" << endl;
cout << "Press:\n(1) For male\n(2) For female, Or\n(3) For not sure." << endl;
cout << "Your Gender: "; cin >> s;
being.setGender(s);
while ( s != '\0' )
{
cout << "\n\nYour selected gender was: " << being.readGender();
switch (being.readGender())
{
case 1:
cout << "\n\nDomination!" << endl;
break;
case 2:
cout << "\n\nPuny little girl!" << endl;
break;
case 3:
cout << "\n\nSeek help, stat!" << endl;
break;
default:
cout << "\n\nYou do not exist!" << endl;
}
}
_getch();
return 0;
}
Gender::Gender()
{
gender = '\0';
}
Gender::~Gender()
{
}
void Gender::setGender(int G)
{
gender = G;
}
int Gender::readGender()
{
return gender;
}