thetan wrote:AgentDerp wrote:1. I don't write code for aesthetics.
I've never met a single good or even decent programmer that doesn't care about the "aesthetics" of their code.
I think it helps out most for two reasons:
1) You're writing a program that you're asking someone esle to read (@ OP) and
2) Random variable names make for having to re-learn all the code again when you come back to look at it six months down the road.
It's still a distant second to the functionality of the code, though. Also, you can't really care that much about elegance about the looks of your code, considering the fact that he's writing in C to begin with.
Contests have been made over making the most god-awful, terse code imaginable. So whoever thinks AgentDerp's code an example of bad aesthetics needs to get out more: he used superfluous newlines and indents for readability and the program itself is quite simple--I'd question how it might be made more 'beautiful' in anyone's opinion (save better named variables).
On the other hand, I have about a hundred ways it could be made LESS readable. So on the aesthetics scale, I definitely don't think AgendDerp's offending the senses here.
So all in all I think it's a good start but I'd heed Goatboy's suggestions for improving the functionality. I'm going to look into this more carefully and post some snippets to improve it in a few.
-- Mon Jul 19, 2010 10:40 pm --
Here's a few tidbits. I kept playing around with it until I changed some things I at first didn't intend to.
Some of the things I thought you might want to look into, per one of goatboy's suggestions, is a switch table. I did some other things that I think might be helpful for you to learn, let me know if you already know them.
- Code: Select all
int get_res(int num1, int num2, int oper)
res = num1 - num2;
res = num1 + num2;
res = num1 % num2;
res = num1 / num2;
res= num1 * num2;
printf("That's not a recognized operator\n");
char oper=0; //I changed this because we know it's going to be a char. This is easier to work with in the get_res() function.
printf("Enter first number[space]second number \n");
scanf("%d %d", &numb1, &numb2);
printf("Enter the ASCII operator: -, +, %, /, or *\n");
result = get_res(numb1, numb2, oper); // I separated this into a function. You could improve this but the idea is to separate potentially reusable things into functions to make life easier for yourself when you go to do it again. :)
printf("The result is: %d", result);