fork(1) download
  1. //------------------------------------------------------------
  2. // Purpose: To implement an interactive horoscope generator.
  3. // The user will enter their birthdate and answer a few
  4. // questions, and the program will print some advice.
  5. //
  6. // Author: John Gauch
  7. // Author: Aaron Estep
  8. //------------------------------------------------------------
  9. #include <cstdlib>
  10. #include <iostream>
  11. #include <cctype>
  12. using namespace std;
  13.  
  14. //------------------------------------------------------------
  15. // Purpose: To make sure that the input variable is an integer
  16. // Input: User birth year and/or birth day.
  17. // Output: The user's birth year, month, day.
  18. //------------------------------------------------------------
  19.  
  20. bool IsInteger(string str)
  21. {
  22. int test = false;
  23. for (int i = 0; i<str.size(); i++)
  24. {
  25. if(isdigit(str[i]))
  26. {
  27. test = true;
  28. }
  29. else
  30. {
  31. test = false;
  32. return false;
  33. }
  34.  
  35. }
  36. return true;
  37. }
  38.  
  39. //------------------------------------------------------------
  40. // Purpose: To prompt the user to enter their name.
  41. // Input: None.
  42. // Output: The user's birth year, month, day.
  43. //------------------------------------------------------------
  44. void WelcomeMessage()
  45. {
  46. cout << "\n ==============================\n";
  47. cout << " ~~~~~~HOROSCOPE GENERATOR~~~~~\n";
  48. cout << " ==============================\n\n";
  49.  
  50. cout << "Greetings from the Great Wizard!\n\n";
  51. cout << "Do you want to know the key to your success in romance, your occupation, \n";
  52. cout << "your family, health and so much more?! Well you're in luck! All you \n";
  53. cout << "must do is enter some information about yourself and I will make your \n";
  54. cout << "wildest dreams come true!\n\n";
  55.  
  56. cout << "********************************************************************\n\n";
  57.  
  58. }
  59.  
  60. //------------------------------------------------------------
  61. // Purpose: To prompt the user to enter their name.
  62. // Input: None.
  63. // Output: The user's birth year, month, day.
  64. //------------------------------------------------------------
  65. void GetName(string & name)
  66. {
  67. // Additional message
  68.  
  69. cout << "First things first! I can’t possibly tell a thing about you if I \n";
  70. cout << "don’t first know your name. Remember, protect your name with all of \n";
  71. cout << "your might. Your name is the key to your soul. . .\n\n";
  72.  
  73. // Prompt user for their name
  74. name = "";
  75. cout << "Enter your first name: ";
  76. cin >> name;
  77.  
  78. cout << "\n********************************************************************\n\n";
  79. }
  80.  
  81. //------------------------------------------------------------
  82. // Purpose: To prompt the user to enter their birthdate.
  83. // Input: None.
  84. // Output: The user's birth year, month, day.
  85. //------------------------------------------------------------
  86. void GetBirthDate(int & year, string & month, int & day, string name)
  87. {
  88. // Additional message
  89. cout << "Excellent work " << name << ". Now, second thing most instrumental ";
  90. cout << "to unlocking of \n";
  91. cout << "your destiny is the alignment of the stars at the time of your birth. \n";
  92. cout << "Provide this information with great care. . .\n\n";
  93.  
  94. // Prompt user for birth year
  95. string temp = "";
  96.  
  97. while ((year < 1900) || (year > 2025))
  98. {
  99. cout << "Enter the year you were born [1900..2025]: ";
  100. cin >> temp;
  101.  
  102. if (IsInteger(temp)) {
  103. year = stoi(temp);
  104. }
  105. else {
  106. year = 0;
  107. }
  108. }
  109.  
  110. // Prompt user for birth month
  111. month = "";
  112. while (month != "Jan" && month != "Feb" && month != "Mar" &&
  113. month != "Apr" && month != "May" && month != "Jun" &&
  114. month != "Jul" && month != "Aug" && month != "Sep" &&
  115. month != "Oct" && month != "Nov" && month != "Dec")
  116. {
  117. cout << "Enter the month you were born [Jan..Dec]: ";
  118. cin >> month;
  119. }
  120.  
  121. // Prompt user for birth day
  122. day = 0;
  123. temp = "";
  124. while ((day < 1) || (day > 31))
  125. {
  126. cout << "Enter the day you were born [1..31]: ";
  127. cin >> temp;
  128.  
  129. if (IsInteger(temp))
  130. {
  131. day = stoi(temp);
  132. }
  133. else
  134. {
  135. day = 0;
  136. }
  137. }
  138. cout << endl << "********************************************************************\n\n";
  139. }
  140.  
  141. //------------------------------------------------------------
  142. // Purpose: To calculate the user's karma.
  143. // Input: None.
  144. // Output: The user's karma score.
  145. //------------------------------------------------------------
  146. int GetKarma(string name)
  147. {
  148. // Additional message
  149. cout << "Very good work indeed, " << name << ". Finally, we must assess your ";
  150. cout << "moral standing. \n";
  151. cout << "In this, we may determine if the spirits are happy with you today, or \n";
  152. cout << "if you best watch your back. . .\n\n";
  153.  
  154. string temp = "";
  155. int answer = -1;
  156.  
  157. while(answer < 0)
  158. {
  159. cout << "How many people have you said hello to today? ";
  160. cin >> temp;
  161. if(IsInteger(temp))
  162. {
  163. answer = stoi(temp);
  164. }
  165. else
  166. {
  167. answer = -1;
  168. }
  169. }
  170.  
  171. cout << endl << "********************************************************************\n\n";
  172.  
  173. // Silly karma calculation
  174. if (answer <= 0)
  175. return 0;
  176. else if (answer == 42)
  177. return 100;
  178. else
  179. return (answer / 2) + (random() % 5);
  180. }
  181.  
  182. //------------------------------------------------------------
  183. // Purpose: Calculate the user's astrological sign.
  184. // Input: The user's birth month, day.
  185. // Output: The user's astrological sign.
  186. //------------------------------------------------------------
  187. string GetSign(const string month, const int day)
  188. {
  189. if ((month == "Mar" && day >= 21) || (month == "Apr" && day <= 20))
  190. return "Aries";
  191. if ((month == "Apr" && day >= 21) || (month == "May" && day <= 21))
  192. return "Taurus";
  193. if ((month == "May" && day >= 22) || (month == "Jun" && day <= 21))
  194. return "Gemini";
  195. if ((month == "Jun" && day >= 22) || (month == "Jul" && day <= 22))
  196. return "Cancer";
  197. if ((month == "Jul" && day >= 23) || (month == "Aug" && day <= 22))
  198. return "Leo";
  199. if ((month == "Aug" && day >= 23) || (month == "Sep" && day <= 23))
  200. return "Virgo";
  201. if ((month == "Sep" && day >= 24) || (month == "Oct" && day <= 23))
  202. return "Libra";
  203. if ((month == "Oct" && day >= 24) || (month == "Nov" && day <= 22))
  204. return "Scorpio";
  205. if ((month == "Nov" && day >= 23) || (month == "Dec" && day <= 21))
  206. return "Sagittarius";
  207. if ((month == "Dec" && day >= 22) || (month == "Jan" && day <= 20))
  208. return "Capricorn";
  209. if ((month == "Jan" && day >= 21) || (month == "Feb" && day <= 19))
  210. return "Aquarius";
  211. if ((month == "Feb" && day >= 20) || (month == "Mar" && day <= 20))
  212. return "Pisces";
  213. return "";
  214. }
  215.  
  216. //------------------------------------------------------------
  217. // Purpose: Romance prediction
  218. // Input: The user's karma score.
  219. // Output: Prediction message.
  220. //------------------------------------------------------------
  221. string Romance(const int karma)
  222. {
  223. int choice = (karma * 17) % 5;
  224. string message = "";
  225. switch(choice)
  226. {
  227. case 0:
  228. message = "~~Maybe your date would like to see a romantic comedy?\n";
  229. break;
  230. case 1:
  231. message = "~~I think it is singles night at the local pub.\n";
  232. break;
  233. case 2:
  234. message = "~~You should sit by the fire and read a good romance novel.\n";
  235. break;
  236. case 3:
  237. message = "~~Searching online for the perfect date seldom works.\n";
  238. break;
  239. case 4:
  240. message = "~~Love is not in the air tonight, time to play video games.\n";
  241. break;
  242. default:
  243. message = "~~Romance prediction is impossible.\n";
  244. break;
  245. }
  246. return message;
  247. }
  248.  
  249. //------------------------------------------------------------
  250. // Purpose: Money prediction
  251. // Input: The user's birth year.
  252. // Output: Prediction message.
  253. //------------------------------------------------------------
  254. void Money(const int year, string & message)
  255. {
  256. int choice = (2025 - year) / 10;
  257. switch(choice)
  258. {
  259. case 0:
  260. message = "~~Ask your parents for their spare change.\n";
  261. break;
  262. case 1:
  263. message = "~~This is a good time to your parents for a bigger allowance.\n";
  264. break;
  265. case 2:
  266. message = "~~You can save more money by buying less beer.\n";
  267. break;
  268. case 3:
  269. message = "~~Try to save a little extra for a down payment on a house.\n";
  270. break;
  271. case 4:
  272. message = "~~Yikes, your children's tuition bills are due soon.\n";
  273. break;
  274. default:
  275. message = "~~Money prediction is impossible.\n";
  276. break;
  277. }
  278. }
  279.  
  280. //------------------------------------------------------------
  281. // Purpose: Job prediction
  282. // Input: The user's birth day and karma score.
  283. // Output: Prediction message.
  284. //------------------------------------------------------------
  285. string Job(const int day, const int karma)
  286. {
  287. string message = "";
  288. if ((day < 15) && (karma > 5))
  289. message = "~~Your boss looks generous today, time to ask for a raise.\n";
  290. else if ((day > 15) && (karma < 5))
  291. message = "~~Prepare for bad news, your company profits are down.\n";
  292. else if ((day == 15) && (karma == 5))
  293. message = "~~Bad news, your company is declaring bankruptcy.\n";
  294. else if (karma > day)
  295. message = "~~Great news, your company just went public!\n";
  296. else if (karma <= day)
  297. message = "~~It looks like a chance for some overtime.\n";
  298. else
  299. message = "~~Money prediction is impossible.\n";
  300.  
  301. return message;
  302. }
  303.  
  304. //------------------------------------------------------------
  305. // Purpose: Family prediction
  306. // Input: name
  307. // Output: Prediction message.
  308. //------------------------------------------------------------
  309.  
  310. string Family(string name)
  311. {
  312. // Use name to determine family predication
  313. int sum = 0;
  314. string message = "";
  315. for (int i = 0; i < name.size(); i++) {
  316. sum = int(name[i]);
  317. }
  318.  
  319. int num = sum % 5;
  320.  
  321. switch (num)
  322. {
  323. case 0:
  324. message = "~~You should say hi to your mother today. She might give you beer.\n";
  325. break;
  326. case 1:
  327. message = "Your father wants to play ball today.\n";
  328. break;
  329. case 2:
  330. message = "~~Your sister is in a bad mood today. Do with this information what you will.\n";
  331. break;
  332. case 3:
  333. message = "~~Your brother is going to play video games today. Try not to interrupt him too much.\n";
  334. break;
  335. case 4:
  336. message = "~~Your family may not be their happiest today. Go make some new friends.\n";
  337. break;
  338. default:
  339. message = "~~Your family will be extremely happy today. Do with this information what you will.\n";
  340. break;
  341. }
  342. return message;
  343. }
  344.  
  345.  
  346. //------------------------------------------------------------
  347. // Purpose: Health prediction
  348. // Input: TO BE ADDED
  349. // Output: Prediction message.
  350. //------------------------------------------------------------
  351.  
  352. string Health(int value) {
  353.  
  354. string health = "";
  355.  
  356. switch(value) {
  357. case 0:
  358. health = "~~Eat extra vegetables today. You will need them.\n";
  359. break;
  360. case 1:
  361. health = "~~Take a brisk walk. Your health is pretty good already.\n";
  362. break;
  363. case 2:
  364. health = "~~Go for a run. The longer the better.\n";
  365. break;
  366. case 3:
  367. health = "~~Stay inside today, or you might catch a cold.\n";
  368. break;
  369. case 4:
  370. health = "~~Go see your doctor today, he might tell you something surprising.\n";
  371. break;
  372. default:
  373. health = "~~Eat as much cake and beer as you want! Your health is invincible!\n";
  374. break;
  375. }
  376. return health;
  377. }
  378.  
  379. //------------------------------------------------------------
  380. // Purpose: Print user's horoscope.
  381. // Input: The user's birth year, month, day, karma.
  382. // Output: None.
  383. //------------------------------------------------------------
  384. void PrintHoroscope(const int year, const string month, const int day,
  385. const int karma, const string name, const int value)
  386. {
  387. // Additional message:
  388. cout << "Congratulations " << name << "!\n\n";
  389. cout << "This is everything I need to know to determine your fate. The time \n";
  390. cout << "has finally come for me to tell you everything you need to know to tip \n";
  391. cout << "the scales in your favor! Remember, with great power comes great responsibility. \n";
  392. cout << "Use this information with care and wisdom. . .\n";
  393.  
  394. cout << endl << "********************************************************************\n\n";
  395.  
  396. // Print user's sign
  397. string sign = GetSign(month,day);
  398. cout << "YOUR ASTROLOGICAL SIGN: ~~" << sign << endl << endl;
  399.  
  400. // Print romance prediction
  401. string romance = Romance(karma);
  402. cout << romance << endl;
  403.  
  404. // Print money prediction
  405. string message = "";
  406. Money(year,message);
  407. cout << message << endl;
  408.  
  409. // Print job prediction
  410. string job = Job(day,karma);
  411. cout << job << endl;
  412.  
  413. // Print family prediction
  414. string family = Family(name);
  415. cout << family << endl;
  416.  
  417. // Print health prediction
  418. string health = Health(value);
  419. cout << health << endl;
  420.  
  421. cout << endl << "********************************************************************\n\n";
  422. }
  423.  
  424. //------------------------------------------------------------
  425. // Purpose: Farewell message.
  426. // Input: None.
  427. // Output: None.
  428. //------------------------------------------------------------
  429. void FarewellMessage(string name)
  430. {
  431. cout << "It's been a wonderous journey together. May the spirits be ever in ";
  432. cout << "your favor. It’s in your hands now. Farewell brave " << name << ". . .\n";
  433.  
  434. cout << endl << "********************************************************************\n\n";
  435.  
  436. cout << " /\\\n";
  437. cout << " / *\\\n";
  438. cout << " / *\\\n";
  439. cout << " / * \\\n";
  440. cout << " | *|\n";
  441. cout << " ___|*______|___\n";
  442. cout << " | @ @ |\n";
  443. cout << " | > |\n";
  444. cout << " { — } /~~~~~~~~~~~~~~~~~~~~~******Have a good day!*****\n";
  445. cout << " ( ) /\n";
  446. cout << " |\\ /| /\n";
  447. cout << " —--| \\ / |--------(>>)/\n";
  448. cout << " / | \\/ |\n";
  449. cout << " / | |\n";
  450. cout << " (<<) | | \n";
  451. cout << " | |\n";
  452. cout << " / \\\n";
  453. cout << " ~~~~~~~~~~~~~~~~~~~~~\n";
  454.  
  455. cout << endl << "********************************************************************\n\n";
  456.  
  457. }
  458.  
  459.  
  460. //------------------------------------------------------------
  461. // Purpose: The main program.
  462. // Input: None.
  463. // Output: None.
  464. //------------------------------------------------------------
  465. int main()
  466. {
  467.  
  468. // Initialize random number generator
  469. srandom(time(NULL));
  470.  
  471. // Random value between 0.5 that may be useful
  472. int value = random() % 5;
  473.  
  474. // Local variables
  475. int year = 0;
  476. string month = "";
  477. int day = 0;
  478. string name = "";
  479.  
  480. // Welcome message
  481. WelcomeMessage();
  482.  
  483. // Get user's name
  484. GetName(name);
  485.  
  486. // Get user's birthday
  487. GetBirthDate(year,month,day,name);
  488.  
  489. // Get user's karma points
  490. int karma = GetKarma(name);
  491.  
  492. // Print full horoscope
  493. PrintHoroscope(year,month,day,karma,name,value);
  494.  
  495. // Farewell message
  496. FarewellMessage(name);
  497.  
  498. return 0;
  499. }
Success #stdin #stdout 0s 5280KB
stdin
Aaron
2002
Sep
14
10
stdout
                   ==============================
                   ~~~~~~HOROSCOPE GENERATOR~~~~~
                   ==============================

Greetings from the Great Wizard!

Do you want to know the key to your success in romance, your occupation, 
your family, health and so much more?! Well you're in luck! All you 
must do is enter some information about yourself and I will make your 
wildest dreams come true!

********************************************************************

First things first! I can’t possibly tell a thing about you if I 
don’t first know your name. Remember, protect your name with all of 
your might. Your name is the key to your soul. . .

Enter your first name: 
********************************************************************

Excellent work Aaron. Now, second thing most instrumental to unlocking of 
your destiny is the alignment of the stars at the time of your birth. 
Provide this information with great care. . .

Enter the year you were born [1900..2025]: Enter the month you were born [Jan..Dec]: Enter the day you were born [1..31]: 
********************************************************************

Very good work indeed, Aaron. Finally, we must assess your moral standing. 
In this, we may determine if the spirits are happy with you today, or 
if you best watch your back. . .

How many people have you said hello to today? 
********************************************************************

Congratulations Aaron!

This is everything I need to know to determine your fate. The time 
has finally come for me to tell you everything you need to know to tip 
the scales in your favor! Remember, with great power comes great responsibility. 
Use this information with care and wisdom. . .

********************************************************************

YOUR ASTROLOGICAL SIGN: ~~Virgo

~~Maybe your date would like to see a romantic comedy?

~~You can save more money by buying less beer.

~~It looks like a chance for some overtime.

~~You should say hi to your mother today. She might give you beer.

~~Go see your doctor today, he might tell you something surprising.


********************************************************************

It's been a wonderous journey together. May the spirits be ever in your favor. It’s in your hands now. Farewell brave Aaron. . .

********************************************************************

              /\
             / *\
            /   *\
           /   *  \
           |      *|
        ___|*______|___
            | @ @ |
            |  >  |
           {   —   }                /~~~~~~~~~~~~~~~~~~~~~******Have a good day!*****
           (        )              /
           |\      /|             /
        —--|  \   / |--------(>>)/
       /   |   \/   |
      /    |        |
    (<<)   |        | 
          |          |
        /              \
     ~~~~~~~~~~~~~~~~~~~~~

********************************************************************