emotional_soup_88

joined 5 days ago

Apart from how unethical it is for a government to target activists instead of inviting them for dialogue, this could have been avoided with decent opsec. Be kind, be educational! ✊❤️‍🔥

It would also be nice to see the Commission reach out to and making good use of all the talented software engineers that reside in the member states, perhaps even trying to evenly distribute outreach, not just focusing on states that produce economic wealth. It would be even nicer to see the Commission realize the benefits of and invest in open source software and hardware in creating the EuroStack.

[–] emotional_soup_88@programming.dev 2 points 4 days ago (1 children)

Thanks! I'm doing this on Linux, which I failed to mention in the post. I terminated the program with ctrl + c, but it was still interesting to me how such a short, seemingly uncomplicated snippet could tax my Ryzen 7 5800 X3D so much that the fans needed to increase their speed. Couldn't a malicious actor theoretically disrupt a target machine by having an unnoticeably insignificant program loop in the background, taxing the CPU to it's usable limits? This is off topic of course, but still interesting.

https://uwuntuos.site/ obvi?

But seriously though, Arch all the way, because it teaches me about Linux and computers, because I can customize all the packages at OS install (without the need for lengthy compiling like Gentoo) and because my Steam games work flawlessly on it.

[–] emotional_soup_88@programming.dev 4 points 4 days ago (3 children)

Thank you so much! :D Yeah, I noticed there were no remainders. I'll try with float and see what I can come up with.

Thanks! Really important to have fun with it too! :)

[–] emotional_soup_88@programming.dev 1 points 4 days ago (3 children)

This is amazing(ly curious)! I put in a letter, the program went into an infinite loop and my chassi fans sped up like crazy.

Checking it out now. Thanks!

[–] emotional_soup_88@programming.dev 1 points 4 days ago (1 children)

Thanks! I really appreciate the more advanced steps too! Now I have something to do next weekend! :D

Looking into it now! Thanks! :)

[–] emotional_soup_88@programming.dev 6 points 5 days ago (2 children)

Signing off now, but I did have the strength left to do this:

else if (choice == 4) {
                        if (num2 == 0) printf("\nhttps://en.wikipedia.org/wiki/Division_by_zero\n\n");
                        else {
                        memory = num1 / num2;
                        printf("\nThe quotient of %d and %d is %d\n\n", num1, num2, memory);
                        }
                }

Cheers!

[–] emotional_soup_88@programming.dev 16 points 5 days ago (4 children)

Thank you! I really appreciate your guidance! It almost feels like you could have experience from teaching or the likes, since you are so good at explaining! Or maybe that just comes with being a senior SE? Either way, thanks again!

 

Please excuse - and do not hesitate to point out - any violation against etiquette that I might be committing here... I am new here.

I started to learn C a few months ago as a hobby as part of a bigger project, namely to learn about computers in general. I have had so much fun reading Code - The Hidden Language of Computer Hardware and Software by Charles Petzold. But that's another story...

I was about to buy a few new SSDs and needed to do some budgeting. Instead of using my phone's calculator, I decided to try to write a calculating program in C, because I hadn't touched programming for some weeks or months because life and I wanted to see if my knowledge had matured some.

The goal was to have it do the four standard arithmetics and also save the last result in a variable, which I just called "memory" for lack of bette phrasing on my part. Maybe next week I'll figure out how to make it possible to use the value saved in memory instead of having to type a number.

I welcome any constructive criticism on how and why this code is up to code or not(sorry...), if it can be improved and how or even if it's just garbage and why that is. I am just proud that it worked without gcc throwing any errors.

#include <stdio.h>

int main(void) {

        int num1 = 0;
        int num2 = 0;
        int choice = 0;
        int memory = 0;

        printf("Welcome to the Calculator of the century!\n\n");

        while (1) {
                printf("What would you like to do?\n\n");
                printf("(1) Add two numbers\n(2) Subtract two numbers\n(3) Multiply two numbers\n(4) Divide two numbers\n(5) Show memory\n(6) Exit\n\n");
                printf("Enter 1, 2, 3, 4, 5 or 6: ");
                scanf("%d", &choice);

                if (choice >= 6 || choice < 1) break;

                if (choice == 5) {
                        printf("\n%d in memory.\n\n", memory);
                } else if (choice < 5 || choice > 0) {
                        printf("\nEnter the first number: ");
                        scanf("%d", &num1);
                        printf("Enter the second number: ");
                        scanf("%d", &num2);
                }

                if (choice == 1) {
                        printf("\nThe sum of %d and %d is %d\n\n", num1, num2, num1 + num2);
                        memory = num1 + num2;
                } else if (choice == 2) {
                        printf("\nThe difference of %d and %d is %d\n\n", num1, num2, num1 - num2);
                        memory = num1 - num2;
                } else if (choice == 3) {
                        printf("\nThe product of %d and %d is %d\n\n", num1, num2, num1 * num2);
                        memory = num1 * num2;
                } else if (choice == 4) {
                        printf("\nThe quotient of %d and %d is %d\n\n", num1, num2, num1 / num2);
                        memory = num1 / num2;
                }
        }

        printf("\nWe hope to see you soon again!\n");
        return 0;
}
view more: next ›