c# – How can I make this calculator code shorter?

I want to make my calculator code shorter.

It is my code:

using System;

namespace ConsoleCalculator
{
    class Program
    {
        static void Main(string() args)
        {
            Console.Title = "ConsoleCalculator";
            int num1, num2 = 0;
            num1 = Convert.ToInt32(Console.ReadLine());
            num2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("ta - Add");
            Console.WriteLine("tb - Subtract");
            Console.WriteLine("tc - Multiply");
            Console.WriteLine("td - Divide");
            Console.WriteLine("te - Power");
            switch (Console.ReadLine())
            {
                case "a":
                    if (num1 + num2 < 50001 & num1 + num2 > -50001 & num1 - num2 < 50001 & num2 - num1 < 50001)
                    {
                        Console.WriteLine($"{num1} + {num2} = " + (num1 + num2));
                    }
                    else
                    {
                        if (num1 + num2 > 50000)
                        {
                            Console.WriteLine("Number is Big");
                        }
                        if (num1 + num2 < -50000)
                        {
                            Console.WriteLine("Number is Small");
                        }
                    }
                    break;
                case "b":
                    if (num1 + num2 < 50001 & num1 + num2 > -50001 & num1 - num2 < 50001 & num2 - num1 < 50001)
                    {
                        Console.WriteLine($"{num1} - {num2} = " + (num1 - num2));
                    }
                    else
                    {
                        if (num1 + num2 > 50000)
                        {
                            Console.WriteLine("Number is Big");
                        }
                        if (num1 + num2 < -50000)
                        {
                            Console.WriteLine("Number is Small");
                        }
                    }
                    break;
                case "c":
                    if (num1 * num2 < 50001 & num1 * num2 > -50001)
                    {
                        Console.WriteLine($"{num1} * {num2} = " + (num1 * num2));
                    }
                    else
                    {
                        if (num1 * num2 > 50000)
                        {
                            Console.WriteLine("Number is Big");
                        }
                        if (num1 * num2 < -50000)
                        {
                            Console.WriteLine("Number is Small");
                        }
                    }
                    break;
                case "d":
                    if (num1 * num2 < 50001 & num1 * num2 > -50001)
                    {
                        Console.WriteLine($"{num1} * {num2} = " + (num1 * num2));
                    }
                    else
                    {
                        if (num1 * num2 > 50000)
                        {
                            Console.WriteLine("Number is Big");
                        }
                        if (num1 * num2 < -50000)
                        {
                            Console.WriteLine("Number is Small");
                        }
                    }
                    break;
                case "e":
                    if (Math.Pow(num1, num2) < 50001 & Math.Pow(num1, num2) > -50001)
                    {
                        Console.WriteLine($"{num1} ^ {num2} = " + Math.Pow(num1, num2));
                    }
                    else
                    {
                        if (Math.Pow(num1, num2) > 50000)
                        {
                            Console.WriteLine("Number is Big");
                        }
                        if (Math.Pow(num1, num2) < -50000)
                        {
                            Console.WriteLine("Number is Small");
                        }
                    }
                    break;
            }
            Console.ReadKey();
        }
    }
}

Can I make this code shorter? Is it possible to do? If it is, how?

text – Convert bulleted and numbered list HTML code to Markdown in AppleScript?

I have this text to manipulate in AppleScript (e.g. the text of a variable):

Example note exported from Apple.

<ul>
  <li>Indent</li>
  <ul>
    <li>*Further* indent</li>
    <ul>
      <li>Even **further **indent. With a (link)(https://duck.com).</li>
    </ul>
  </ul>
</ul>

End note.

I’m converting it all to Markdown from HTML. I need to clean up this remaining bit of HTML which is the bullet list, so that the result is:

Example note exported from Apple.

- Indent
    - *Further* indent
        - Even **further **indent. With a (link)(https://duck.com).

End note.

It has to be able to cater to nested indenting with some rich text inside the items such as this example. I prefer Markdown output to use hyphens and either a tab or two spaces for the indenting.

It also has to be containable inside the applescript – no external .py files etc, and to not require homebrew or a third party tool to be installed.

visual studio code – Open a local folder in a VSCode Remote-SSH session

I am using Microsoft Visual Studio Code 1.50.1 on Windows 10.

I’d like to develop on a remote virtual machine running in Amazon Elastic Compute Cloud (EC2). This works fine, but I can’t open a local directory on the remote VM.

I would specifically like to be able to mount a local folder on my development system as my working directory. The functionality I’m seeking is similar to how the Remote-Containers extension works, where you can mount a directory into a container.

Question: Is it possible to mount a local folder into a Remote-SSH session in VSCode? If so, how?

code – Developer wanted to build and maintain WP Template

Hello boys and girls,

I am looking for somebody who can write the perfect code. :]

We just launched a new affiliate company. There is a team that has some great SEO and statistics. Also, there is some excellent funding behind it. Of course, the budget is intended to go to content and marketing as much as possible. But as we are planning to build a significant number of websites, we are looking to use an Exclusive WordPress Template. We want to develop this template ourselves. Every website will have the same basics, and this should be in the template. The focus is on SEO, lightweight, and super fast.

We need someone to join our team to build this template, help maintain, and work on any request from within the group.

We would prefer a Dutch native. If you are that person or if you know that person please get in touch.

numerical integration – how to write code for trapezoid rule

Find an example of a function f(x) on an interval (a,b) so that the midpoint (or trapezoid) rule gives the maximum possible error. Show the midpoint or trapezoid rule computation, computation of the exact value of the integral, the maximum error estimate, and the actual error.

unity – Every X months Visual Studio Code says: ‘UI’ does not exist in the namespace ‘UnityEngine’

I’ve tried countless fixes in the last 1,5 year, and I still don’t know what is the absolute fix for this. Or after fixing it, why it got fixed.

Usually this happens after a Unity update, or after updating the IDE packages.

I tried lots of fixes, and it seems like that it’s always changing what fixes it:

  • Sometimes it’s fixed by regenerating all projects files, also sometimes manually deleting them.

  • Sometimes it’s fixed by reinstalling Visual Studio.

  • Sometimes it’s fixed by downgrading the IDE packages (until now not for me, but based on some browsing, it works for some people)

  • Switching to Visual Studio in the preferences, opening it, then switching back to Code. (At first I thought that this is just regenerates the projects files, but who knows, maybe it does something else in the background.)

(I always restart Unity and Code after these)

Sometimes it isn’t fixed by just going through this list one by one. Sometimes none of them fix it, so I try them all again, in different order, etc, and then it’s fixed after some random combination.

Most of the times only Visual Studio Code is broken, but sometimes Visual Studio is missing the references as well.

Could someone tell me why this keeps occurring for a lot of people, and what is the absolute fix and why?

Who wants FileCrypt Invite Code?

hi everyone, i’ve got filecrypt code, Who wants? :]

pointers – Buffer Overflow issue in C code

I’ve been writing the following bit of code, and someone had informed me that it runs of the risk of having a buffer overflow.

Now admittedly my knowledge of buffer overflows may be not be as robust as I would like, but I thought that a buffer overflow is when the data being written will not fit within the bounderies of the buffer and will spill over to adjacent memory location.

I assumed that the problem may be related to the fread, that it wouldn’t be a safe function to use, but reading through the documentation doesn’t seem to tell me that its unsafe like say strcpy() is compared to strncpy(). So I’m rather uncertain on where the problem could be located or how to handle it. And also if anyone has any suggestions on where I can go (or what book to read) that would help expand my knowledge on this subject or other vulnerability weaknesses, I would be appreciative.

bool readLong(FILE *f, long *n)
{
    unsigned char *ptr,tmp;

    if (fread(n,8,1,f) != 1)
        return false;

    ptr = (unsigned char *)n;
    tmp = ptr(0);
    ptr(0) = ptr(7);
    ptr(7) = tmp;
    tmp = ptr(1);
    ptr(1) = ptr(6);
    ptr(6) = tmp;
    tmp = ptr(2);
    ptr(2) = ptr(5);
    ptr(5) = tmp;
    tmp = ptr(3);
    ptr(3) = ptr(4);
    ptr(4) = tmp;

    return true;
}

filecrypt code now is avalaible

Hi everyone.
I got 1 filecrypt invite code, i will give theme to active and good uploaders who need filecrypt account
if you want invite code just let me know

java – Bank Card Generator Code

This program is used to create a random bank card number. Card number is created using account type and client location for the first eight digits and the remaining 8 digits are completely random. I’m new to this site, but I believe it’s just for code review to get opinions on code. If i’m incorrect please let me know and I can take this down. Otherwise, feel free to give me feedback. Thanks!

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    private static ArrayList<String> storedCardNumbers = new ArrayList<String>();

    public static void main(String() args) {

        menu();

    }

    //create menu for checking list of cards or creating a new card
    public static void menu(){
        //used to check if client wants to exit program
        boolean exit = false;

        System.out.println("___________________n" +
                "Welcome to our bank!n" + "Choose an option below: n" +
                "1. Create new bank card.n" +
                "2. Check existing cards.n" +
                "3. Exit.");
        Scanner scanner = new Scanner(System.in);
        int choice = scanner.nextInt();

        if(choice == 1) {
            createNewCard();
        } else if(choice == 2){
            System.out.println("-------------------------");
            System.out.println("There are " + storedCardNumbers.size() + " cards in the system");
            for (int i = 0; i < storedCardNumbers.size(); i++) {
                System.out.println(storedCardNumbers.get(i).toString());
            }
            System.out.println("-------------------------");
        } else if(choice == 3) {
            System.out.println("Thank you for coming in!");
            exit = true;
        } else {
                System.out.println("Incorrect choice.n" +
                        "Please choose a valid option: ");
                menu();
            }

        if(exit == false) {
            System.out.println("Would you like to do anything else?");
            menu();
        } else {

        }
        }


    //create new bank card with user params
    public static String createNewCard() {
//        String accountType = setCardAccountType();
//        String location = setAccountLocation();
        String cardNumber = getCardNumber(setCardAccountType(),setAccountLocation());
        System.out.println("New card successfully created.n" +
                "Your new bank card number is: n" +
                cardNumber);
        storedCardNumbers.add(cardNumber);
        return cardNumber;
        }

        public static String setAccountLocation() {

            String location = "other";

            System.out.println("What is your location?n" +
                    "1. US Eastn" +
                    "2. US Westn" +
                    "3. Hawaiin" +
                    "4. Alaskan" +
                    "5. Other.");
            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();

            if (choice == 1) {
                location.equalsIgnoreCase("useast");
            } else if (choice == 2) {
                location.equalsIgnoreCase("uswest");
            } else if (choice == 3) {
                location.equalsIgnoreCase("alaska");
            } else if (choice == 4) {
                location.equalsIgnoreCase("hawaii");
            } else if(choice == 5) {
                location.equalsIgnoreCase("other");
            }else {
                System.out.println("Entered invalid selection.n" +
                        "Please enter valid selection.");
                setCardAccountType();
            }

            return location;
        }

        //set the card account type for the creatNewCard method to use
        public static String setCardAccountType() {

            String accountType = "other";

            System.out.println("Which type of account do you have?n" +
                    "1. Checking.n" +
                    "2. Savings.n" +
                    "3. Credit.n" +
                    "4. Other.n" +
                    "Enter corresponding digit: ");
            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();

            if (choice == 1) {
                accountType.equalsIgnoreCase("checking");
            } else if (choice == 2) {
                accountType.equalsIgnoreCase("savings");
            } else if (choice == 3) {
                accountType.equalsIgnoreCase("credit");
            } else if (choice == 4) {
                accountType.equalsIgnoreCase("other");
            } else {
                System.out.println("Entered invalid selection.n" +
                        "Please enter valid selection.");
                setCardAccountType();
            }

            return accountType;
        }

    //create random number for card
    public static int getRandom(int min, int max) {
        return (int) (Math.random()*(max - min)) + min;
    }

    public static String getCardNumber(String accountType, String location) {
        //first set of four
        int accountKeySet;
        //second set of four
        int locationKeySet;
        //third set of four
        int lastEightFirst;
        //fourth set of four
        int lastEightSecond;

        //assign a value to each account type
        if(accountType.equalsIgnoreCase("checking")) {
            accountKeySet = 4400;
        } else if(accountType.equalsIgnoreCase("savings")) {
            accountKeySet = 4300;
        } else if(accountType.equalsIgnoreCase("credit")) {
            accountKeySet = 4200;
        } else {
            accountKeySet = 4000;
        }


        //Assign a value to each location of client
        if(location.equalsIgnoreCase("useast")) {
            locationKeySet = 1011;
        } else if(location.equalsIgnoreCase("uswest")) {
            locationKeySet = 2011;
        } else if (location.equalsIgnoreCase("Alaska")) {
            locationKeySet = 3011;
        } else if (location.equalsIgnoreCase("hawaii")) {
            locationKeySet = 4011;
        } else {
            locationKeySet = 1022;
        }

        //create a randomized number for last of card number
        lastEightFirst = getRandom(1000,9999);
        lastEightSecond = getRandom(1000,9999);

        //construct card number
        StringBuilder key = new StringBuilder();
        key.append(accountKeySet);
        key.append(" ");
        key.append(locationKeySet);
        key.append(" ");
        key.append(lastEightFirst);
        key.append(" ");
        key.append(lastEightSecond);
        return key.toString();
    }
}