Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace LoveCalc
- {
- /// <summary>
- /// An application that takes 2 peoples first and last name and then compares them to the word loves.
- /// Counts how many of the letters from loves apears in the names and then gives a 5 digit total.
- /// Each individual number then gets added. For example
- /// L 2
- /// O 0
- /// V 0
- /// E 3
- /// S 2
- /// 2+0,0+0,0+3,3+2 = 2,0,3,5
- /// 2+0,0+3,3+5
- /// etc until you are left with a 2 digit number representing the percentage of love
- /// I have also added a section that you can use to impress your partner by setting a default message
- /// when you enter you and your partners name
- /// </summary>
- class Program
- {
- static void Main(string[] args)
- {
- while (true) //Loop used to keep asking for user input.
- {
- Console.ForegroundColor = ConsoleColor.Magenta;
- Console.WriteLine("**************************************************");
- Console.WriteLine("****************** ****** ******************");
- Console.WriteLine("**************** ** ****************");
- Console.WriteLine("*************** ***************");
- Console.WriteLine("*************** LOVE CALCULATOR ***************");
- Console.WriteLine("*************** ***************");
- Console.WriteLine("**************** ****************");
- Console.WriteLine("***************** *****************");
- Console.WriteLine("******************* *******************");
- Console.WriteLine("********************** **********************");
- Console.WriteLine("************************ ************************");
- Console.WriteLine("**************************************************");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine();
- //Ask for the users name and their partners name and define a string for each.
- Console.WriteLine("Welcome to the Love Calculator.");
- Console.WriteLine();
- Console.Write("Please enter YOUR FIRST name: ");
- string yourNameOne = Console.ReadLine();
- Console.WriteLine();
- Console.Write("Now enter YOUR LAST name: ");
- string yourNameTwo = Console.ReadLine();
- Console.WriteLine();
- Console.Write("Please enter your PARTNERS FIRST name: ");
- string partnerNameOne = Console.ReadLine();
- Console.WriteLine();
- Console.Write("Now enter your PARTNERS LAST name: ");
- string partnerNameTwo = Console.ReadLine();
- Console.WriteLine();
- // Send the names to be calculated by a function
- int totalCompatability = LoveCalculation(yourNameOne, yourNameTwo, partnerNameOne, partnerNameTwo);
- // Display the calculated number that is used for the compatability score.
- Console.ForegroundColor = ConsoleColor.Magenta;
- Console.WriteLine("Compatability Score: " + totalCompatability + "%");
- Console.WriteLine();
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write("<enter> to continue, <esc> or q to quit: "); //Tell the user to use <esc> or q to quit.
- var key = (int)Console.ReadKey(true).Key; //Retrieve the user input
- if (key == 27 /* <esc> key*/ || key == 81 /* letter q*/)
- break;
- Console.Clear(); //Clear the console for the next try.
- }
- }
- /// <summary>
- /// This function is used to calculate the compatability rate. It takes the names and notes how many times
- /// the letter from the word LOVES appears within the string and then adds them together individually
- /// 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
- /// 2 digit number.
- /// </summary>
- /// <param name="combinedNames"></param>
- /// <returns></returns>
- static int LoveCalculation(string nameOne, string nameTwo, string nameThree, string nameFour)
- {
- // Concatenate strings and make uppercase so that it is easier to compare
- // incase people do or do not use capitals for starting their name.
- string concatNames = nameOne + nameTwo + nameThree + nameFour;
- string upperNames = concatNames.ToUpper();
- // Check for your predetermined string. Here I have set me and my girlfriend
- // If it finds it it outputs the function called PreSetString which is found at the bottom of the code.
- if (upperNames == "RACHELSTRAUGHANDEANTEARSE" || upperNames == "DEANTEARSERACHELSTRAUGHAN")
- {
- PreSetString();
- }
- // Count how many of the letters from the word LOVES appears within the string created from the
- // users input of names.
- // *** I had to find the code from StackOverflow for this part ***
- int countL = upperNames.Split('L').Length - 1;
- int countO = upperNames.Split('O').Length - 1;
- int countV = upperNames.Split('V').Length - 1;
- int countE = upperNames.Split('E').Length - 1;
- int countS = upperNames.Split('S').Length - 1;
- // Run first calculation of L+O, O+V, V+E, E+S
- int lO = countL + countO;
- int oV = countO + countV;
- int vE = countV + countE;
- int eS = countE + countS;
- // Run next calculation
- int loov = lO + oV;
- int ovve = oV + vE;
- int vees = vE + eS;
- // Run next calculation - We're nearly there!
- int loovovve = loov + ovve;
- int ovvevees = ovve + vees;
- // Concatenate final 2 numbers to create compatability percentage
- // *** I had to find the code from StackOverflow for this part ***
- int total = Convert.ToInt32(string.Format("{0}{1}", loovovve, ovvevees));
- // An additional calculation is needed if the final number is 3 digits rather than 2.
- // For an example the final 2 numbers could be a 5 and a 9 which would would be concatenated
- // to a figure showing 59% however is you got a 15 and a 9 the the figure would show as 159
- // so here we check the length of the number and if its 3 we do an additional calculation.
- // *** I had to find the code from StackOverflow for this part ***
- string totalString = total.ToString();
- while (totalString.Length >= 3)
- {
- if (totalString.Length == 3)
- {
- string[] x = new string[totalString.Length];
- for (int i = 0; i < totalString.Length; i++)
- {
- x[i] = totalString.Substring(i, 1);
- }
- int finalNum1 = Convert.ToInt32(x[0]);
- int finalNum2 = Convert.ToInt32(x[1]);
- int finalNum3 = Convert.ToInt32(x[2]);
- int newTotal1 = finalNum1 + finalNum2;
- int newTotal2 = finalNum2 + finalNum3;
- total = Convert.ToInt32(string.Format("{0}{1}", newTotal1, newTotal2));
- }
- // This if statement is the same as above but looks for a length of 4 in case you returned
- //something like an 11 and a 12 which would return 1112% so we need further calculations to
- // return a 2 digit number.
- if (totalString.Length == 4)
- {
- string[] x = new string[totalString.Length];
- for (int i = 0; i < totalString.Length; i++)
- {
- x[i] = totalString.Substring(i, 1);
- }
- int finalNum1 = Convert.ToInt32(x[0]);
- int finalNum2 = Convert.ToInt32(x[1]);
- int finalNum3 = Convert.ToInt32(x[2]);
- int finalNum4 = Convert.ToInt32(x[3]);
- int newTotal1 = finalNum1 + finalNum2;
- int newTotal2 = finalNum2 + finalNum3;
- int newTotal3 = finalNum3 + finalNum4;
- int nextTotal1 = newTotal1 + newTotal2;
- int nextTotal2 = newTotal2 + newTotal3;
- total = Convert.ToInt32(string.Format("{0}{1}", nextTotal1, nextTotal2));
- }
- totalString = total.ToString();
- }
- return total;
- }
- /// <summary>
- /// This code is ran if your predetermined string is matched. It shows a default message and score and then the real score.
- /// </summary>
- static void PreSetString()
- {
- Console.ForegroundColor = ConsoleColor.Magenta;
- Console.WriteLine("There is no couple in the world that belongs together more than you two!");
- Console.Write("\nCompatability Score: 100%\n");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine();
- Console.WriteLine("Your Real Score is: ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement