C calculator I made:

Dedicated to "idiots" right here on HTS! Please give them a "thanks" for free LULZ. However, please keep the flaming to yourselves!
Forum rules
Content must be appropriate. Keep the flaming to yourselves! For LULZ purposes only.

Re: C calculator I made:

Post by msbachman on Mon Jul 19, 2010 9:54 pm
([msg=42188]see Re: C calculator I made:[/msg])

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. :lol:

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
    #include <stdio.h>


int get_res(int num1, int num2, int oper)
{
int res;
switch (oper)
{
case '-':
res = num1 - num2;
break;
case '+':
res = num1 + num2;
break;
case '%':
res = num1 % num2;
break;
case '/':
res = num1 / num2;
break;
case '*':
res= num1 * num2;
break;
default:
printf("That's not a recognized operator\n");


}


return res;


}

   void main(void)
    {
        int numb1=0;
        int numb2=0;
        int result=0;
        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");
        scanf("\n%c", &oper);

   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);

 
    }
"I'm going to get into your sister. I'm going to get my hands on your daughter."
~Gatito
User avatar
msbachman
Contributor
Contributor
 
Posts: 685
Joined: Mon Jan 12, 2009 10:22 pm
Location: In the sky lol
Blog: View Blog (0)


Re: C calculator I made:

Post by sanddbox on Mon Jul 19, 2010 11:41 pm
([msg=42192]see Re: C calculator I made:[/msg])

You wanted to mold a shitty calculator that even my grandmother wouldn't be impressed with and SHOW IT OFF? Then you come here asking for constructive criticism and completely ignore what we tell you?

First of all, regardless of who's reading it your code should always be legible. It's a good habit and it also makes it much easier to debug (plus if you drop a project and come back 6 months later it's a godsend).

Second of all, you're being disrespectful to a community of people trying to help you write better code. If you're just here to show a program that a retarded treefrog with autism could have made with one hand while sleeping, then you should leave now.

I can't tell if you're being serious about the 6th grade thing and I honestly don't give a shit about your post enough to re-read it, but they teach negatives in 4th grade and I figured out negatives on my own by second grade. Stop making excuses.
Image

HTS User Composition:
95% Male
4.98% Female
.01% Monica
.01% Goat
User avatar
sanddbox
Expert
Expert
 
Posts: 2337
Joined: Sat Jul 04, 2009 5:20 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by fashizzlepop on Mon Jul 19, 2010 11:52 pm
([msg=42195]see Re: C calculator I made:[/msg])

There's no point, sandy and Bach. This kid is an idiot. IF he wanted our help he wouldn't go all piss-shit. Let's not waste our time on him and let this thread die and not waste our time.

Kiss your ass good bye, mate.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2304
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by AgentDerp on Tue Jul 20, 2010 2:37 pm
([msg=42264]see Re: C calculator I made:[/msg])

sanddbox wrote:You wanted to mold a shitty calculator that even my grandmother wouldn't be impressed with and SHOW IT OFF? Then you come here asking for constructive criticism and completely ignore what we tell you?

First of all, regardless of who's reading it your code should always be legible. It's a good habit and it also makes it much easier to debug (plus if you drop a project and come back 6 months later it's a godsend).

Second of all, you're being disrespectful to a community of people trying to help you write better code. If you're just here to show a program that a retarded treefrog with autism could have made with one hand while sleeping, then you should leave now.

I can't tell if you're being serious about the 6th grade thing and I honestly don't give a shit about your post enough to re-read it, but they teach negatives in 4th grade and I figured out negatives on my own by second grade. Stop making excuses.

WELL EXCUSE ME.
It must be my damn fault that I live in a sh*tty state, go to a sh*tty school, and have a sh*tty attitude (that is true).
I am sorry for not meeting your excellent expectations master Sanddbox.
What must I do to meet them?

Well, 1. I wasn't asking for "constructive criticism". I was asking people to try out the code. I might not even come back to my calculator in 6 months because it is a sh*tty piece of sh*t according to you.

2. I was showing a program that a retarded treefrog with autism could have made with one hand while sleeping. Should I give you my exact house address so you can stab me slowly with a sharp knife and laugh maniacally so I won't be able to post anymore vulgarities to your perfect forum of perfect people? :roll:

3. I am not making damn excuses. As I said before, my school is sh*tty and didn't teach me *anything* to do with damn motherf***in' negatives. Everything that is coming out of my sh*tty mouth right in this post is truth.


If you don't like my sh*tty sh*t calculator made from a sh*tty person with no sh*tty intelligence about sh*t, TOO F***IN' BAD.[/pissedoff]
AgentDerp
New User
New User
 
Posts: 13
Joined: Mon Jul 19, 2010 4:56 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by sanddbox on Tue Jul 20, 2010 3:11 pm
([msg=42265]see Re: C calculator I made:[/msg])

Let me get this straight. You can't figure out negatives on your own? They're the opposite of positives.
Image

HTS User Composition:
95% Male
4.98% Female
.01% Monica
.01% Goat
User avatar
sanddbox
Expert
Expert
 
Posts: 2337
Joined: Sat Jul 04, 2009 5:20 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by Bren2010 on Tue Jul 20, 2010 3:53 pm
([msg=42266]see Re: C calculator I made:[/msg])

How old are you that you never learned negative numbers?!? :o It's a standard. Either you chose not to learn it, or you missed the day they talked about it. I reversed modulo (even though you probably don't know what that is) by myself, and I'm 15.
User avatar
Bren2010
Poster
Poster
 
Posts: 340
Joined: Fri Sep 19, 2008 3:23 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by sanddbox on Tue Jul 20, 2010 3:54 pm
([msg=42268]see Re: C calculator I made:[/msg])

He said he's in 6th grade (which is past when you should learn negatives).
Here you go:

5 / 5 (that means 5 divided by 5) = 1
5 / -5 = -1

10 / 2 = 5
10 / -2 = -5

I don't see why you have to understand negatives to program anyway - your program is doing the math, not you.
Image

HTS User Composition:
95% Male
4.98% Female
.01% Monica
.01% Goat
User avatar
sanddbox
Expert
Expert
 
Posts: 2337
Joined: Sat Jul 04, 2009 5:20 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by Bren2010 on Tue Jul 20, 2010 4:05 pm
([msg=42270]see Re: C calculator I made:[/msg])

Eh, I didn't know negatives until 7th grade. My 5th grade teacher would never teach math and science, only literature and we were with her all day. Once I got into middle school and we had different teachers I realized how suffocated I was.

-10 / 2 = -5
-10 / -2 = 5

mult and div rules:
positive with positive is positive
negative with positive is negative
negative with negative is positive
User avatar
Bren2010
Poster
Poster
 
Posts: 340
Joined: Fri Sep 19, 2008 3:23 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by AgentDerp on Tue Jul 20, 2010 5:08 pm
([msg=42285]see Re: C calculator I made:[/msg])

sanddbox wrote:He said he's in 6th grade (which is past when you should learn negatives).
Here you go:

5 / 5 (that means 5 divided by 5) = 1
5 / -5 = -1

10 / 2 = 5
10 / -2 = -5

I don't see why you have to understand negatives to program anyway - your program is doing the math, not you.

So that means 12 / -4 is -3?
AgentDerp
New User
New User
 
Posts: 13
Joined: Mon Jul 19, 2010 4:56 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by Bren2010 on Tue Jul 20, 2010 5:19 pm
([msg=42286]see Re: C calculator I made:[/msg])

Yup. ;)
User avatar
Bren2010
Poster
Poster
 
Posts: 340
Joined: Fri Sep 19, 2008 3:23 pm
Blog: View Blog (0)


PreviousNext

Return to Idiots' Corner

Who is online

Users browsing this forum: No registered users and 0 guests