I am receiving a run time error

I am working on a homework problem and I am receiving a runtime check failure #3: the variable selection is being used with out being initiated.

I am trying to fix it but don't know where to start.
This is one file of the three made to this problem.

Date file: date.cpp
#include "Astrology.cpp"
#include <iostream>
using namespace std;

Date::Date()
{

}

Date::Date(int m, int d, int y)
{
set (m,d,y);
}

void Date::input()
// preconditions: date is entered in mm/dd/yyyy format
// postconditions: values for current object are changed to input values
{
char char1;
cout << "Enter the date in the following format mm/dd/yyyy >";
cin >> month >> char1 >> day >> char1 >> year;
}

void Date::output()
// preconditions: none
// postconditions: date is displayed in mm/dd/yyyy format
{
cout << month << "/" << day << '/' << year << endl;
}

void Date::set(int new_month, int new_day, int new_year)
//Precondition: new_month and new_day form a possible date.
//Postcondition: The date is reset according to the arguments.
{
month = new_month;
day = new_day;
year = new_year;
}

bool Date::operator ==(Date rightSide)
// preconditions: none
// postconditions: return true when rightSide.day and rightSide.month are the same
// as day and month
// otherwise returns false
{
bool same = false;
if ( day == rightSide.day && month == rightSide.month )
same = true;

return same;
}

void Date::SetSign()
{
int zodiac=0;


enum Zodiac {aries, taurus, gemini, cancer, leo, virgo, libra, scorpio, sagittarius, capricorn, aquarius, pisces};
Zodiac selection;

if (month==3&&day>=21 || month==4&&day<20)
zodiac = 0;
else if(month==4&&day>=21 || month==5&&day<=21)
zodiac = 1;
else if(month==5&&day>=22 || month==6&&day<=21)
zodiac = 2;
else if(month==6&&day>=22 || month==7&&day<=22)
zodiac = 3;
else if(month==7&&day>=23 || month==8&&day<=21)
zodiac = 4;
else if(month==8&&day>=22 || month==9&&day<=23)
zodiac = 5;
else if(month==9&&day>=24 || month==10&&day<=23)
zodiac = 6;
else if(month==10&&day>=24 || month==11&&day<=22)
zodiac = 7;
else if(month==11&&day>=23 || month==12&&day<=22)
zodiac = 8;
else if(month==12&&day>=23 || month==1&&day<=20)
zodiac = 9;
else if(month==1&&day>=21 || month==2&&day<=19)
zodiac = 10;
else if(month==2&&day>=20 || month==2&&day<=20)
zodiac = 11;

switch(zodiac)
{
case 0: Sign = aries; break;
case 1: Sign = taurus; break;
case 2: Sign = gemini; break;
case 3: Sign = cancer; break;
case 4: Sign = leo; break;
case 5: Sign = virgo; break;
case 6: Sign = libra; break;
case 7: Sign = scorpio; break;
case 8: Sign = sagittarius; break;
case 9: Sign = capricorn; break;
case 10: Sign = aquarius; break;
case 11: Sign = pisces; break;
}

selection == Sign;

switch(selection)
{
case aries: cout << " Aries\n"; break;
case taurus: cout << " Taurus\n";break;
case gemini: cout << " Gemini\n"; break;
case cancer: cout << " Cancer\n"; break;
case leo: cout << " Leo\n";break;
case virgo: cout << " Virgo\n"; break;
case libra: cout << " Libra\n"; break;
case scorpio: cout << " Scorpio\n";break;
case sagittarius: cout << " Sagittarius\n"; break;
case capricorn: cout << " Capricorn\n"; break;
case aquarius: cout << " Aquarius\n";break;
case pisces: cout << " Pisces\n"; break;
}
}
----------------------------------------------------------------
The test file

#include "Astrology.cpp"
#include <iostream>

using namespace std;


int main()
{

Date today;

today.input();

cout << "\n Today is: ";
today.output();

Date birthday;

cout << " When is your birthday? ";
birthday.input();

cout << " Your birthday is ";
birthday.output();


Date ShowZodiac;

cout << "\nYour zodiac sign is ";
ShowZodiac.SetSign();

if (today == birthday)
cout << "\n\nHappy Birthday!\n\n";
return 0;
}
------------------------------------------------------------------------
Astrology file


#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>

enum Zodiac {aries, taurus, gemini, cancer, leo, virgo, libra, scorpio, sagittarius, capricorn, aquarius, pisces};
enum Element {fire, water, air, earth};

class Date
{
public:
Date(int month, int day, int year);
Date();

void input(); // Get Player's choice
void output();
void set(int new_month, int new_day, int new_year);
void SetSign();
void ShowSign(enum Zodiac);

bool Date::operator ==(Date rightSide);

private:

Zodiac selection;
int Zodiac, Sign;
int month, day, year;
};

when I enter the date and birth day the sign does not pop up, just the runtime failure.

Please help
if you're creating multifile app then you should use header files.ie.

 
#include "header.h"     // not #include "header.cpp" 


header.h will have all the declarations and header.cpp will have the definitions.
Do you have call stack when it breaks? Can you trace it to the offending line in your code?

nevermind. think i've spotted it:
selection == Sign;

looks dodgy. You want to do some kind of assignment maybe?

(although even then you are trying to assign a Zodiac enum to an int..)

edit: wait a minute.. why can't you print out your starsigns in the first switch statement. why effectively try and do the same thing twice?
Last edited on
simptri69

do I need to create a new item then and erase the old files with .cpp?
No. it has nothing to do with that.
Read my post.
mutexe,

how would I print out the star signs in the first statement?
you can use one switch statement by doing this instead.
case 0: Sign = aries; cout <<"Aries\n"; break;

I haven't looked for your original problem, but that is how you print out the star signs in one switch statement.
hackmattr,

would I just put
case 0: Sign = aries; cout <<"Aries\n"; break;

and then do it for each one changing the case number to increase for each one?
Topic archived. No new replies allowed.