this is the finished code. im posting this here because i already started and why not;
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
public void calculate(string string_a, string string_b, int num_1, int num_2, int num_3, int num_4)
{
int is_1_2_close = 0;
int is_3_4_close = 0;
if (num_1 > num_2)
{
if ((num_1 - num_2) <= 20)
{
is_1_2_close = 0; // yes
}
else
{
is_1_2_close = 1; // no
}
}
else if (num_2 > num_1)
{
if ((num_2 - num_1) <= 20)
{
is_1_2_close = 0; // yes
}
else
{
is_1_2_close = 1; // no
}
}
else
{
is_1_2_close = 0; // yes
}
///////////////
if (num_3 > num_4)
{
if ((num_3 - num_4) <= 20)
{
is_3_4_close = 0; // yes
}
else
{
is_3_4_close = 1; // no
}
}
else if (num_4 > num_3)
{
if ((num_4 - num_3) <= 20)
{
is_3_4_close = 0; // yes
}
else
{
is_3_4_close = 1; // no
}
}
else
{
is_3_4_close = 0; // yes
}
///////////////
Console.WriteLine("\r\n////////////////\r\nresults:\r\n");
if ((is_1_2_close == 0) && (is_3_4_close == 1))
{
Console.WriteLine("\"" + string_a + "\"");
Console.WriteLine("+");
Console.WriteLine("\"" + string_b + "\"");
Console.WriteLine("=");
Console.WriteLine("confident");
}
else if ((is_1_2_close == 1) && (is_3_4_close == 1) && (num_1 > num_2) && (num_4 > num_3))
{
Console.WriteLine("\"" + string_a + "\"");
Console.WriteLine("+");
Console.WriteLine("\"" + string_b + "\"");
Console.WriteLine("=");
Console.WriteLine("confident");
}
else if ((is_1_2_close == 1) && (is_3_4_close == 1) && (num_2 > num_1) && (num_3 > num_4))
{
Console.WriteLine("\"" + string_a + "\"");
Console.WriteLine("+");
Console.WriteLine("\"" + string_b + "\"");
Console.WriteLine("=");
Console.WriteLine("confident");
}
else
{
Console.WriteLine("\"" + string_a + "\"");
Console.WriteLine("+");
Console.WriteLine("\"" + string_b + "\"");
Console.WriteLine("=");
Console.WriteLine("not confident");
}
}
public void fit_into_100(string string_a, string string_b, ref int num_3, ref int num_4)
{
string_a = string_a.Replace(" ", String.Empty);
string_b = string_b.Replace(" ", String.Empty);
double counter = 0;
double counter_a = string_a.Length;
double counter_b = string_b.Length;
foreach (char c in string_a)
{
char temp_1 = c;
foreach (char d in string_b)
{
char temp_2 = d;
if (temp_1 == temp_2)
{
counter++;
}
}
}
// percentage=(yourNumber/totalNumber)*100;
double make_percentage_one = (counter / counter_a) * 100;
double make_percentage_two = (counter / counter_b) * 100;
int percentage_one = (int)make_percentage_one;
int percentage_two = (int)make_percentage_two;
// number * percentage / 100
double one = counter_a * 100 / (counter_a + counter_b);
double two = counter_b * 100 / (counter_a + counter_b);
int a_one = (int)one;
int a_two = (int)two;
num_3 = a_one;
num_4 = a_two;
Console.WriteLine("\r\nstring holds what percentage of the total shared char:");
Console.WriteLine(a_one);
Console.WriteLine(a_two);
}
public static string RemoveDuplicates(string input)
{
return new string(input.ToCharArray().Distinct().ToArray());
}
public void length_of_string(string string_a, string string_b, ref int num_1, ref int num_2)
{
string a = RemoveDuplicates(string_a);
string b = RemoveDuplicates(string_b);
a = a.Replace(" ", String.Empty);
b = b.Replace(" ", String.Empty);
double counter = 0;
double counter_a = a.Length;
double counter_b = b.Length;
foreach (char c in a)
{
char temp_1 = c;
foreach (char d in b)
{
char temp_2 = d;
if (temp_2 == ' ') continue;
if (temp_1 == temp_2)
{
counter++;
break;
}
}
}
// percentage=(yourNumber/totalNumber)*100;
double one = (counter / counter_a) * 100;
double two = (counter / counter_b) * 100;
int a_one = (int)one;
int a_two = (int)two;
if (a_one > a_two)
{
a_one = 100 - a_two;
}
else if (a_two > a_one)
{
a_two = 100 - a_one;
}
else if (a_two == a_one)
{
a_one = 50;
a_two = 50;
}
num_1 = a_one;
num_2 = a_two;
Console.WriteLine("\r\nsmaller value is: the shared char is what total percentage of the string:");
Console.WriteLine(a_one);
Console.WriteLine(a_two);
}
static void Main(string[] args)
{
int num_1 = 0;
int num_2 = 0;
int num_3 = 0;
int num_4 = 0;
Program string_descriptin = new Program();
string string_a = "coffee time";
//string ok = "so i shot him";
string string_b = "ok";
Console.WriteLine("- " + string_a);
Console.WriteLine("- " + string_b);
string_descriptin.length_of_string(string_a, string_b, ref num_1, ref num_2);
string_descriptin.fit_into_100(string_a, string_b, ref num_3, ref num_4);
string_descriptin.calculate(string_a, string_b, num_1, num_2, num_3, num_4);
Console.ReadLine();
}
}
}
my results;
Code:
- coffee time
- ok
smaller value is: the shared char is what total percentage of the string:
14
86
string holds what percentage of the total shared char:
83
16
////////////////
results:
"coffee time"
+
"ok"
=
confident
Press any key to continue . . .
////////////////////////////////////
last post in this thread unless theres a bug.