Advertisement
Dosk3n

LoveCalc

Mar 2nd, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LoveCalc
  8. {
  9.     /// <summary>
  10.     /// An application that takes 2 peoples first and last name and then compares them to the word loves.
  11.     /// Counts how many of the letters from loves apears in the names and then gives a 5 digit total.
  12.     /// Each individual number then gets added. For example
  13.     /// L 2
  14.     /// O 0
  15.     /// V 0
  16.     /// E 3
  17.     /// S 2
  18.     /// 2+0,0+0,0+3,3+2 = 2,0,3,5
  19.     /// 2+0,0+3,3+5
  20.     /// etc until you are left with a 2 digit number representing the percentage of love
  21.     /// I have also added a section that you can use to impress your partner by setting a default message
  22.     /// when you enter you and your partners name
  23.     /// </summary>
  24.     class Program
  25.     {
  26.         static void Main(string[] args)
  27.         {
  28.             while (true) //Loop used to keep asking for user input.
  29.             {
  30.                 Console.ForegroundColor = ConsoleColor.Magenta;
  31.                 Console.WriteLine("**************************************************");
  32.                 Console.WriteLine("******************    ******    ******************");
  33.                 Console.WriteLine("****************        **        ****************");
  34.                 Console.WriteLine("***************                    ***************");
  35.                 Console.WriteLine("***************  LOVE CALCULATOR   ***************");
  36.                 Console.WriteLine("***************                    ***************");
  37.                 Console.WriteLine("****************                  ****************");
  38.                 Console.WriteLine("*****************                *****************");
  39.                 Console.WriteLine("*******************            *******************");
  40.                 Console.WriteLine("**********************      **********************");
  41.                 Console.WriteLine("************************  ************************");
  42.                 Console.WriteLine("**************************************************");
  43.                 Console.ForegroundColor = ConsoleColor.White;
  44.                 Console.WriteLine();
  45.  
  46.                 //Ask for the users name and their partners name and define a string for each.
  47.                 Console.WriteLine("Welcome to the Love Calculator.");
  48.                 Console.WriteLine();
  49.                 Console.Write("Please enter YOUR FIRST name: ");
  50.                 string yourNameOne = Console.ReadLine();
  51.                 Console.WriteLine();
  52.                 Console.Write("Now enter YOUR LAST name: ");
  53.                 string yourNameTwo = Console.ReadLine();
  54.                 Console.WriteLine();
  55.                 Console.Write("Please enter your PARTNERS FIRST name: ");
  56.                 string partnerNameOne = Console.ReadLine();
  57.                 Console.WriteLine();
  58.                 Console.Write("Now enter your PARTNERS LAST name: ");
  59.                 string partnerNameTwo = Console.ReadLine();
  60.                 Console.WriteLine();
  61.  
  62.                 // Send the names to be calculated by a function
  63.                 int totalCompatability = LoveCalculation(yourNameOne, yourNameTwo, partnerNameOne, partnerNameTwo);
  64.                
  65.                 // Display the calculated number that is used for the compatability score.
  66.                 Console.ForegroundColor = ConsoleColor.Magenta;
  67.                 Console.WriteLine("Compatability Score: " + totalCompatability + "%");
  68.                 Console.WriteLine();
  69.                 Console.ForegroundColor = ConsoleColor.White;
  70.  
  71.                 Console.Write("<enter> to continue, <esc> or q to quit: "); //Tell the user to use <esc> or q to quit.
  72.                 var key = (int)Console.ReadKey(true).Key; //Retrieve the user input
  73.                 if (key == 27 /* <esc> key*/ || key == 81 /* letter q*/)
  74.                     break;
  75.                 Console.Clear(); //Clear the console for the next try.
  76.             }
  77.         }
  78.  
  79.         /// <summary>
  80.         /// This function is used to calculate the compatability rate. It takes the names and notes how many times
  81.         /// the letter from the word LOVES appears within the string and then adds them together individually
  82.         /// for example: L+O, O+V, V+E, E+S then does the same with the total of each of those until it has a
  83.         /// 2 digit number.
  84.         /// </summary>
  85.         /// <param name="combinedNames"></param>
  86.         /// <returns></returns>
  87.         static int LoveCalculation(string nameOne, string nameTwo, string nameThree, string nameFour)
  88.         {
  89.             // Concatenate strings and make uppercase so that it is easier to compare
  90.             // incase people do or do not use capitals for starting their name.
  91.             string concatNames = nameOne + nameTwo + nameThree + nameFour;
  92.             string upperNames = concatNames.ToUpper();
  93.  
  94.             // Check for your predetermined string. Here I have set me and my girlfriend
  95.             // If it finds it it outputs the function called PreSetString which is found at the bottom of the code.
  96.             if (upperNames == "RACHELSTRAUGHANDEANTEARSE" || upperNames == "DEANTEARSERACHELSTRAUGHAN")
  97.             {
  98.                 PreSetString();
  99.             }
  100.  
  101.             // Count how many of the letters from the word LOVES appears within the string created from the
  102.             // users input of names.
  103.             // *** I had to find the code from StackOverflow for this part ***
  104.             int countL = upperNames.Split('L').Length - 1;
  105.             int countO = upperNames.Split('O').Length - 1;
  106.             int countV = upperNames.Split('V').Length - 1;
  107.             int countE = upperNames.Split('E').Length - 1;
  108.             int countS = upperNames.Split('S').Length - 1;
  109.  
  110.             // Run first calculation of L+O, O+V, V+E, E+S
  111.             int lO = countL + countO;
  112.             int oV = countO + countV;
  113.             int vE = countV + countE;
  114.             int eS = countE + countS;
  115.  
  116.             // Run next calculation
  117.             int loov = lO + oV;
  118.             int ovve = oV + vE;
  119.             int vees = vE + eS;
  120.  
  121.             // Run next calculation - We're nearly there!
  122.             int loovovve = loov + ovve;
  123.             int ovvevees = ovve + vees;
  124.  
  125.             // Concatenate final 2 numbers to create compatability percentage
  126.             // *** I had to find the code from StackOverflow for this part ***
  127.             int total = Convert.ToInt32(string.Format("{0}{1}", loovovve, ovvevees));
  128.  
  129.             // An additional calculation is needed if the final number is 3 digits rather  than 2.
  130.             // For an example the final 2 numbers could be a 5 and a 9 which would would be concatenated
  131.             // to a figure showing 59% however is you got a 15 and a 9 the the figure would show as 159
  132.             // so here we check the length of the number and if its 3 we do an additional calculation.
  133.             // *** I had to find the code from StackOverflow for this part ***
  134.             string totalString = total.ToString();
  135.            
  136.             while (totalString.Length >= 3)
  137.             {
  138.  
  139.                  if (totalString.Length == 3)
  140.                 {
  141.                     string[] x = new string[totalString.Length];
  142.                     for (int i = 0; i < totalString.Length; i++)
  143.                     {
  144.                         x[i] = totalString.Substring(i, 1);
  145.                     }
  146.  
  147.                     int finalNum1 = Convert.ToInt32(x[0]);
  148.                     int finalNum2 = Convert.ToInt32(x[1]);
  149.                     int finalNum3 = Convert.ToInt32(x[2]);
  150.  
  151.                     int newTotal1 = finalNum1 + finalNum2;
  152.                     int newTotal2 = finalNum2 + finalNum3;
  153.  
  154.                     total = Convert.ToInt32(string.Format("{0}{1}", newTotal1, newTotal2));
  155.  
  156.                 }
  157.  
  158.                 // This if statement is the same as above but looks for a length of 4 in case you returned
  159.                 //something like an 11 and a 12 which would return 1112% so we need further calculations to
  160.                 // return a 2 digit number.
  161.                 if (totalString.Length == 4)
  162.                 {
  163.                     string[] x = new string[totalString.Length];
  164.                     for (int i = 0; i < totalString.Length; i++)
  165.                     {
  166.                         x[i] = totalString.Substring(i, 1);
  167.                     }
  168.  
  169.                     int finalNum1 = Convert.ToInt32(x[0]);
  170.                     int finalNum2 = Convert.ToInt32(x[1]);
  171.                     int finalNum3 = Convert.ToInt32(x[2]);
  172.                     int finalNum4 = Convert.ToInt32(x[3]);
  173.  
  174.                     int newTotal1 = finalNum1 + finalNum2;
  175.                     int newTotal2 = finalNum2 + finalNum3;
  176.                     int newTotal3 = finalNum3 + finalNum4;
  177.  
  178.                     int nextTotal1 = newTotal1 + newTotal2;
  179.                     int nextTotal2 = newTotal2 + newTotal3;
  180.  
  181.                     total = Convert.ToInt32(string.Format("{0}{1}", nextTotal1, nextTotal2));
  182.  
  183.                 }
  184.                 totalString = total.ToString();
  185.  
  186.             }
  187.  
  188.             return total;
  189.         }
  190.  
  191.         /// <summary>
  192.         /// This code is ran if your predetermined string is matched. It shows a default message and score and then the real score.
  193.         /// </summary>
  194.         static void PreSetString()
  195.         {
  196.             Console.ForegroundColor = ConsoleColor.Magenta;
  197.             Console.WriteLine("There is no couple in the world that belongs together more than you two!");
  198.             Console.Write("\nCompatability Score: 100%\n");
  199.             Console.ForegroundColor = ConsoleColor.White;
  200.             Console.WriteLine();
  201.             Console.WriteLine("Your Real Score is: ");
  202.            
  203.            
  204.         }
  205.     }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement