Guest User

Submission to r/badcode challenge #30

a guest
Feb 21st, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.07 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void help()
  5. {
  6.  cout << "Help: Follow the instructions to get the love quotient*** of two people! Start by inputing the names! \nSmall text:\n*The product doesn't perform actual magic.\n**All of this is bullshit. It doesn't actually have anything to do with love.\n***The love quotient doesn't actually show love\n****That might not necessarily be true." << endl;
  7. }
  8.  
  9. int quo(string name)
  10. {
  11.  int len = name.length();
  12.  int midnum = len / 2;
  13.  char first = name[0];
  14.  char last = name[len];
  15.  char mid = name[midnum];
  16.  int firn = first;
  17.  int midn = mid;
  18.  int lasn = last;
  19.  //cout << "DEBUG: " << midn << " " << firn << " " << lasn << " ";
  20.  string type;
  21.  if(len <= 5)
  22.  {
  23.   type = "short";
  24.  } else if(5 < len < 10)
  25.  {
  26.   type = "medium";
  27.  } else if(len >= 10)
  28.  {
  29.   type = "long";
  30.  } else
  31.  {
  32.   return -1;
  33.  }
  34.  int sum = firn + lasn + midn - len;
  35.  int after;
  36.  if(type == "short")
  37.  {
  38.   after = sum * 23;
  39.  }else if(type == "medium")
  40.  {
  41.   after = sum * 432; // some serious "A = 432 Hz" conspiracy here!
  42.  }else if(type == "long")
  43.  {
  44.   after = sum * 666;
  45.  }else
  46.  {
  47.   return -1;
  48.  }
  49.  int fin = after + len;
  50.  int per = fin % 100;
  51.  return per;
  52. }
  53.  
  54. int process()
  55. {
  56.  //intro
  57.    
  58.  string input;
  59.  string name1;
  60.  string name2;
  61.  bool validN1 = false;
  62.  bool validN2 = false;
  63.    
  64.  //get first name
  65.  getline(cin, input);
  66.  while(validN1 == false)
  67.  {
  68.   if(input == "/help")
  69.   //Nice
  70.   {
  71.    help();
  72.    cout << "Now input the first name!" << endl;
  73.    getline(cin, input);
  74.    validN1 = false;
  75.   } else if (input.length() == 0)
  76.   {
  77.    cout << "You have to write something! Input the name:" << endl;
  78.    validN1 = false;
  79.    getline(cin, input);
  80.   } else
  81.   {
  82.    name1 = input;
  83.    cout << "Now enter the second name!" << endl;
  84.    validN1 = true;
  85.   }
  86.  }
  87.    
  88.  //get second name
  89.  getline(cin, input);
  90.  while(validN2 == false)
  91.  {
  92.   if(input == "/help")
  93.   {
  94.    help();
  95.    cout << "Now input the second name!" << endl;
  96.    getline(cin, input);
  97.    validN2 = false;
  98.   } else if (input.length() == 0)
  99.   {
  100.    cout << "You have to write something! Input the name:" << endl;
  101.    validN2 = false;
  102.    getline(cin, input);
  103.   } else
  104.   {
  105.    name2 = input;
  106.    validN2 = true;
  107.   }
  108.  }
  109.    
  110.  //compute indexes
  111.  int index1 = quo(name1);
  112.  if(index1 < 0)
  113.  {
  114.   cout << "There was an error calculating the first person's quotient!";
  115.   return 0;
  116.  }
  117.  int index2 = quo(name2);
  118.  if(index2 < 0)
  119.  {
  120.   cout << "There was an error calculating the second person's quotient!";
  121.   return 0;
  122.  }
  123.  if(name1 == name2)
  124.  {
  125.   index2 = (index2 * 443) % 100;
  126.  }
  127.    
  128.  //finale computing
  129.  int lqo = 100 - (abs(index1 - index2));
  130.  if(lqo <= 10)
  131.  {
  132.   cout << "You're not likely to fall in love! Your score is ";
  133.  } else if(lqo <= 25)
  134.  {
  135.   cout << "You have a small chance! Your score is ";
  136.  } else if(lqo <= 50)
  137.  {
  138.   cout << "You have some chance! Your score is ";
  139.  } else if(lqo <= 85)
  140.  {
  141.   cout << "You have a pretty good chance! Your score is ";
  142.  } else if(lqo < 100)
  143.  {
  144.   cout << "You have a great chance! Your score is ";
  145.  }else if(lqo == 100)
  146.  {
  147.   cout << "You're a perfect match! Your score is ";
  148.  } else
  149.  {
  150.   cout << "There was an error calculating.";
  151.   return 0;
  152.  }
  153.  cout << lqo << " points out of 100!" << endl;
  154.  return 0;
  155. }
  156.  
  157. int main()
  158. {
  159.  cout << "Welcome to Definitely Not Mymokol's Magic* Machine™! This machine allows you to input two names, do all sorts of magical somethings and it will output how much love is between you two**! Start by typing in the names or type \"/help\" if you for whatever reason think you should." << endl;
  160.  bool doProc = true;
  161.  bool procDone = false;
  162.  while(procDone == false)
  163.  {
  164.   process();
  165.   procDone = true;
  166.   cout << "Would you like to try again? Answer yes or no:" << endl;
  167.   string ans;
  168.   bool asked = false;
  169.   while(asked == false)
  170.   {
  171.    getline(cin, ans);
  172.    if(ans == "yes" || ans == "Yes" || ans == "YES")
  173.    {
  174.     doProc = true;
  175.     asked = true;
  176.     cout << "Type in the first name:" << endl;
  177.    } else if(ans == "no" || ans == "No" || ans == "NO")
  178.    {
  179.     doProc = false;
  180.     cout << "Closing the application!";
  181.     return 0;
  182.    } else if(ans == "/help")
  183.    {
  184.     help();
  185.     asked = false;
  186.     cout << "Now answer yes or no:" << endl;
  187.    } else
  188.    {
  189.     cout << "You have to answer yes or no!" << endl;
  190.     asked = false;
  191.    }
  192.   }
  193.   asked = false;
  194.  }
  195.  while(doProc == true && procDone == true)
  196.  {
  197.   process();
  198.   cout << "Would you like to try again? Answer yes or no:" << endl;
  199.   string ans;
  200.   bool asked = false;
  201.   while(asked == false)
  202.   {
  203.    getline(cin, ans);
  204.    if(ans == "yes" || ans == "Yes" || ans == "YES")
  205.    {
  206.     doProc = true;
  207.     asked = true;
  208.     cout << "Type in the first name:" << endl;
  209.    } else if(ans == "no" || ans == "No" || ans == "NO")
  210.    {
  211.     doProc = false;
  212.     cout << "Closing the application!";
  213.     return 0;
  214.    } else if(ans == "/help")
  215.    {
  216.     help();
  217.     asked = false;
  218.     cout << "Now answer yes or no:" << endl;
  219.    } else
  220.    {
  221.     cout << "You have to answer yes or no!" << endl;
  222.     asked = false;
  223.    }
  224.   }
  225.   asked = false;
  226.  }
  227. }
Advertisement
Add Comment
Please, Sign In to add comment