//------------------------------------------------------------
// Purpose: To implement an interactive horoscope generator.
// The user will enter their birthdate and answer a few
// questions, and the program will print some advice.
//
// Author: John Gauch
// Author: Aaron Estep
//------------------------------------------------------------
#include <cstdlib>
#include <iostream>
#include <cctype>
using namespace std;
//------------------------------------------------------------
// Purpose: To make sure that the input variable is an integer
// Input: User birth year and/or birth day.
// Output: The user's birth year, month, day.
//------------------------------------------------------------
bool IsInteger(string str)
{
int test = false;
for (int i = 0; i<str.size(); i++)
{
if(isdigit(str[i]))
{
test = true;
}
else
{
test = false;
return false;
}
}
return true;
}
//------------------------------------------------------------
// Purpose: To prompt the user to enter their name.
// Input: None.
// Output: The user's birth year, month, day.
//------------------------------------------------------------
void WelcomeMessage()
{
cout << "\n ==============================\n";
cout << " ~~~~~~HOROSCOPE GENERATOR~~~~~\n";
cout << " ==============================\n\n";
cout << "Greetings from the Great Wizard!\n\n";
cout << "Do you want to know the key to your success in romance, your occupation, \n";
cout << "your family, health and so much more?! Well you're in luck! All you \n";
cout << "must do is enter some information about yourself and I will make your \n";
cout << "wildest dreams come true!\n\n";
cout << "********************************************************************\n\n";
}
//------------------------------------------------------------
// Purpose: To prompt the user to enter their name.
// Input: None.
// Output: The user's birth year, month, day.
//------------------------------------------------------------
void GetName(string & name)
{
// Additional message
cout << "First things first! I can’t possibly tell a thing about you if I \n";
cout << "don’t first know your name. Remember, protect your name with all of \n";
cout << "your might. Your name is the key to your soul. . .\n\n";
// Prompt user for their name
name = "";
cout << "Enter your first name: ";
cin >> name;
cout << "\n********************************************************************\n\n";
}
//------------------------------------------------------------
// Purpose: To prompt the user to enter their birthdate.
// Input: None.
// Output: The user's birth year, month, day.
//------------------------------------------------------------
void GetBirthDate(int & year, string & month, int & day, string name)
{
// Additional message
cout << "Excellent work " << name << ". Now, second thing most instrumental ";
cout << "to unlocking of \n";
cout << "your destiny is the alignment of the stars at the time of your birth. \n";
cout << "Provide this information with great care. . .\n\n";
// Prompt user for birth year
string temp = "";
while ((year < 1900) || (year > 2025))
{
cout << "Enter the year you were born [1900..2025]: ";
cin >> temp;
if (IsInteger(temp)) {
year = stoi(temp);
}
else {
year = 0;
}
}
// Prompt user for birth month
month = "";
while (month != "Jan" && month != "Feb" && month != "Mar" &&
month != "Apr" && month != "May" && month != "Jun" &&
month != "Jul" && month != "Aug" && month != "Sep" &&
month != "Oct" && month != "Nov" && month != "Dec")
{
cout << "Enter the month you were born [Jan..Dec]: ";
cin >> month;
}
// Prompt user for birth day
day = 0;
temp = "";
while ((day < 1) || (day > 31))
{
cout << "Enter the day you were born [1..31]: ";
cin >> temp;
if (IsInteger(temp))
{
day = stoi(temp);
}
else
{
day = 0;
}
}
cout << endl << "********************************************************************\n\n";
}
//------------------------------------------------------------
// Purpose: To calculate the user's karma.
// Input: None.
// Output: The user's karma score.
//------------------------------------------------------------
int GetKarma(string name)
{
// Additional message
cout << "Very good work indeed, " << name << ". Finally, we must assess your ";
cout << "moral standing. \n";
cout << "In this, we may determine if the spirits are happy with you today, or \n";
cout << "if you best watch your back. . .\n\n";
string temp = "";
int answer = -1;
while(answer < 0)
{
cout << "How many people have you said hello to today? ";
cin >> temp;
if(IsInteger(temp))
{
answer = stoi(temp);
}
else
{
answer = -1;
}
}
cout << endl << "********************************************************************\n\n";
// Silly karma calculation
if (answer <= 0)
return 0;
else if (answer == 42)
return 100;
else
return (answer / 2) + (random() % 5);
}
//------------------------------------------------------------
// Purpose: Calculate the user's astrological sign.
// Input: The user's birth month, day.
// Output: The user's astrological sign.
//------------------------------------------------------------
string GetSign(const string month, const int day)
{
if ((month == "Mar" && day >= 21) || (month == "Apr" && day <= 20))
return "Aries";
if ((month == "Apr" && day >= 21) || (month == "May" && day <= 21))
return "Taurus";
if ((month == "May" && day >= 22) || (month == "Jun" && day <= 21))
return "Gemini";
if ((month == "Jun" && day >= 22) || (month == "Jul" && day <= 22))
return "Cancer";
if ((month == "Jul" && day >= 23) || (month == "Aug" && day <= 22))
return "Leo";
if ((month == "Aug" && day >= 23) || (month == "Sep" && day <= 23))
return "Virgo";
if ((month == "Sep" && day >= 24) || (month == "Oct" && day <= 23))
return "Libra";
if ((month == "Oct" && day >= 24) || (month == "Nov" && day <= 22))
return "Scorpio";
if ((month == "Nov" && day >= 23) || (month == "Dec" && day <= 21))
return "Sagittarius";
if ((month == "Dec" && day >= 22) || (month == "Jan" && day <= 20))
return "Capricorn";
if ((month == "Jan" && day >= 21) || (month == "Feb" && day <= 19))
return "Aquarius";
if ((month == "Feb" && day >= 20) || (month == "Mar" && day <= 20))
return "Pisces";
return "";
}
//------------------------------------------------------------
// Purpose: Romance prediction
// Input: The user's karma score.
// Output: Prediction message.
//------------------------------------------------------------
string Romance(const int karma)
{
int choice = (karma * 17) % 5;
string message = "";
switch(choice)
{
case 0:
message = "~~Maybe your date would like to see a romantic comedy?\n";
break;
case 1:
message = "~~I think it is singles night at the local pub.\n";
break;
case 2:
message = "~~You should sit by the fire and read a good romance novel.\n";
break;
case 3:
message = "~~Searching online for the perfect date seldom works.\n";
break;
case 4:
message = "~~Love is not in the air tonight, time to play video games.\n";
break;
default:
message = "~~Romance prediction is impossible.\n";
break;
}
return message;
}
//------------------------------------------------------------
// Purpose: Money prediction
// Input: The user's birth year.
// Output: Prediction message.
//------------------------------------------------------------
void Money(const int year, string & message)
{
int choice = (2025 - year) / 10;
switch(choice)
{
case 0:
message = "~~Ask your parents for their spare change.\n";
break;
case 1:
message = "~~This is a good time to your parents for a bigger allowance.\n";
break;
case 2:
message = "~~You can save more money by buying less beer.\n";
break;
case 3:
message = "~~Try to save a little extra for a down payment on a house.\n";
break;
case 4:
message = "~~Yikes, your children's tuition bills are due soon.\n";
break;
default:
message = "~~Money prediction is impossible.\n";
break;
}
}
//------------------------------------------------------------
// Purpose: Job prediction
// Input: The user's birth day and karma score.
// Output: Prediction message.
//------------------------------------------------------------
string Job(const int day, const int karma)
{
string message = "";
if ((day < 15) && (karma > 5))
message = "~~Your boss looks generous today, time to ask for a raise.\n";
else if ((day > 15) && (karma < 5))
message = "~~Prepare for bad news, your company profits are down.\n";
else if ((day == 15) && (karma == 5))
message = "~~Bad news, your company is declaring bankruptcy.\n";
else if (karma > day)
message = "~~Great news, your company just went public!\n";
else if (karma <= day)
message = "~~It looks like a chance for some overtime.\n";
else
message = "~~Money prediction is impossible.\n";
return message;
}
//------------------------------------------------------------
// Purpose: Family prediction
// Input: name
// Output: Prediction message.
//------------------------------------------------------------
string Family(string name)
{
// Use name to determine family predication
int sum = 0;
string message = "";
for (int i = 0; i < name.size(); i++) {
sum = int(name[i]);
}
int num = sum % 5;
switch (num)
{
case 0:
message = "~~You should say hi to your mother today. She might give you beer.\n";
break;
case 1:
message = "Your father wants to play ball today.\n";
break;
case 2:
message = "~~Your sister is in a bad mood today. Do with this information what you will.\n";
break;
case 3:
message = "~~Your brother is going to play video games today. Try not to interrupt him too much.\n";
break;
case 4:
message = "~~Your family may not be their happiest today. Go make some new friends.\n";
break;
default:
message = "~~Your family will be extremely happy today. Do with this information what you will.\n";
break;
}
return message;
}
//------------------------------------------------------------
// Purpose: Health prediction
// Input: TO BE ADDED
// Output: Prediction message.
//------------------------------------------------------------
string Health(int value) {
string health = "";
switch(value) {
case 0:
health = "~~Eat extra vegetables today. You will need them.\n";
break;
case 1:
health = "~~Take a brisk walk. Your health is pretty good already.\n";
break;
case 2:
health = "~~Go for a run. The longer the better.\n";
break;
case 3:
health = "~~Stay inside today, or you might catch a cold.\n";
break;
case 4:
health = "~~Go see your doctor today, he might tell you something surprising.\n";
break;
default:
health = "~~Eat as much cake and beer as you want! Your health is invincible!\n";
break;
}
return health;
}
//------------------------------------------------------------
// Purpose: Print user's horoscope.
// Input: The user's birth year, month, day, karma.
// Output: None.
//------------------------------------------------------------
void PrintHoroscope(const int year, const string month, const int day,
const int karma, const string name, const int value)
{
// Additional message:
cout << "Congratulations " << name << "!\n\n";
cout << "This is everything I need to know to determine your fate. The time \n";
cout << "has finally come for me to tell you everything you need to know to tip \n";
cout << "the scales in your favor! Remember, with great power comes great responsibility. \n";
cout << "Use this information with care and wisdom. . .\n";
cout << endl << "********************************************************************\n\n";
// Print user's sign
string sign = GetSign(month,day);
cout << "YOUR ASTROLOGICAL SIGN: ~~" << sign << endl << endl;
// Print romance prediction
string romance = Romance(karma);
cout << romance << endl;
// Print money prediction
string message = "";
Money(year,message);
cout << message << endl;
// Print job prediction
string job = Job(day,karma);
cout << job << endl;
// Print family prediction
string family = Family(name);
cout << family << endl;
// Print health prediction
string health = Health(value);
cout << health << endl;
cout << endl << "********************************************************************\n\n";
}
//------------------------------------------------------------
// Purpose: Farewell message.
// Input: None.
// Output: None.
//------------------------------------------------------------
void FarewellMessage(string name)
{
cout << "It's been a wonderous journey together. May the spirits be ever in ";
cout << "your favor. It’s in your hands now. Farewell brave " << name << ". . .\n";
cout << endl << "********************************************************************\n\n";
cout << " /\\\n";
cout << " / *\\\n";
cout << " / *\\\n";
cout << " / * \\\n";
cout << " | *|\n";
cout << " ___|*______|___\n";
cout << " | @ @ |\n";
cout << " | > |\n";
cout << " { — } /~~~~~~~~~~~~~~~~~~~~~******Have a good day!*****\n";
cout << " ( ) /\n";
cout << " |\\ /| /\n";
cout << " —--| \\ / |--------(>>)/\n";
cout << " / | \\/ |\n";
cout << " / | |\n";
cout << " (<<) | | \n";
cout << " | |\n";
cout << " / \\\n";
cout << " ~~~~~~~~~~~~~~~~~~~~~\n";
cout << endl << "********************************************************************\n\n";
}
//------------------------------------------------------------
// Purpose: The main program.
// Input: None.
// Output: None.
//------------------------------------------------------------
int main()
{
// Initialize random number generator
srandom(time(NULL));
// Random value between 0.5 that may be useful
int value = random() % 5;
// Local variables
int year = 0;
string month = "";
int day = 0;
string name = "";
// Welcome message
WelcomeMessage();
// Get user's name
GetName(name);
// Get user's birthday
GetBirthDate(year,month,day,name);
// Get user's karma points
int karma = GetKarma(name);
// Print full horoscope
PrintHoroscope(year,month,day,karma,name,value);
// Farewell message
FarewellMessage(name);
return 0;
}