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 sanddbox on Wed Jul 21, 2010 1:10 am
([msg=42333]see Re: C calculator I made:[/msg])

He's demonstrated a [small] will to learn, so I'm going to put his earlier immaturity aside and help him as best I can.

@msbachman: You're being too easy on him.
Image

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


Re: C calculator I made:

Post by fashizzlepop on Wed Jul 21, 2010 2:50 pm
([msg=42350]see Re: C calculator I made:[/msg])

No. Microscopic, if even existent, will to learn. And "immaturity?" more like a complete dick, disrespectful, and dillusional with an absence of ANY common sense. Not to mention the attitude that he even aimed at YOU sanddbox. I don't see why he hasn't been completely flamed up and out his ass.
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: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by sanddbox on Wed Jul 21, 2010 3:10 pm
([msg=42352]see Re: C calculator I made:[/msg])

fashizzlepop wrote:No. Microscopic, if even existent, will to learn. And "immaturity?" more like a complete dick, disrespectful, and dillusional with an absence of ANY common sense. Not to mention the attitude that he even aimed at YOU sanddbox. I don't see why he hasn't been completely flamed up and out his ass.


Like I said, he appears to have gotten his earlier douchiness. Plus, he's the only 6th grader I've ever seen that actually uses proper spelling and grammar.
Image

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


Re: C calculator I made:

Post by Goatboy on Wed Jul 21, 2010 3:13 pm
([msg=42353]see Re: C calculator I made:[/msg])

We don't know how old he is. I can claim to be, and act as if I am, any age I want. I'm only justifying my own decision here. I won't stop you from helping him. But I do think you should reconsider. What kind of message are we sending by feeding him?
Assume that everything I say is or could be a lie.
1UHQ15HqBRZFykqx7mKHpYroxanLjJcUk
User avatar
Goatboy
Expert
Expert
 
Posts: 2785
Joined: Mon Jul 07, 2008 9:35 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by sanddbox on Wed Jul 21, 2010 3:18 pm
([msg=42354]see Re: C calculator I made:[/msg])

I wouldn't give two horse shits about his age if it wasn't actually relevant to this thread. It's not the age itself but the level of education that gives him the disadvantage.
Image

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


Re: C calculator I made:

Post by cilpolir on Wed Jul 21, 2010 3:21 pm
([msg=42355]see Re: C calculator I made:[/msg])

I got the next code:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
float calculator(float number1, float number2, char teken)
{
    switch(teken)
    {
        case '-':
        return number1-number2;
        break;
        case '+':
        return number1+number2;
        break;
        case '*':
        return number1*number2;
        break;
        case '/':
        return number1/number2;
        default:
        printf("operator not recognised");
    }
}


int main ()
{
    float number1;
    float number2;
    char teken;

    printf("Welcome to my calculator :D");
    while(1)
    {
    printf("\nplease enter the first number(0 to exit): ");
    scanf("%f",&number1);
    if(number1==0)break;
    printf("\nplease enter the operator: ");
    scanf("%s",&teken);
    printf("\nplease enter the second number: ");
    scanf("%f",&number2);
    printf("\nThe result is: %f",calculator(number1,number2,teken));
    }
}

but when I change the "%s" to "%c" it just skips the scanf("%c",&teken) anyone knows why?
Image
User avatar
cilpolir
Poster
Poster
 
Posts: 214
Joined: Sat Sep 12, 2009 10:46 am
Blog: View Blog (0)


Re: C calculator I made:

Post by msbachman on Wed Jul 21, 2010 6:23 pm
([msg=42378]see Re: C calculator I made:[/msg])

Since you're new to C, newlines probably don't make sense as of yet.

If you were to look at a hexdump of whatever you send over via scanf, you'll see typically that what's going over is something like the following:

Code: Select all
303132333435363738390a


That last character, 0a, is what's causing you your problem; it's the character sent over by pressing the enter key.

The quick fix to this is to take this line and do the following:

Code: Select all
   scanf("\n%s",&teken);


Another fix you could try would be to enter in your first number and press Ctrl+D. I didn't test this but that should work as well. FYI this key combo sends over the EOF.

A good study question would be to look into how to print the value of the EOF. It's easy once you do it once but it might be good practice.
"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: 681
Joined: Mon Jan 12, 2009 10:22 pm
Location: In the sky lol
Blog: View Blog (0)


Re: C calculator I made:

Post by AgentDerp on Wed Jul 21, 2010 9:17 pm
([msg=42393]see Re: C calculator I made:[/msg])

fashizzlepop wrote:No. Microscopic, if even existent, will to learn. And "immaturity?" more like a complete dick, disrespectful, and dillusional with an absence of ANY common sense. Not to mention the attitude that he even aimed at YOU sanddbox. I don't see why he hasn't been completely flamed up and out his ass.

You get a cookie AND a gold star for describing me perfectly with every single detail.
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 fashizzlepop on Wed Jul 21, 2010 9:43 pm
([msg=42396]see Re: C calculator I made:[/msg])

AgentDerp wrote:
fashizzlepop wrote:No. Microscopic, if even existent, will to learn. And "immaturity?" more like a complete dick, disrespectful, and dillusional with an absence of ANY common sense. Not to mention the attitude that he even aimed at YOU sanddbox. I don't see why he hasn't been completely flamed up and out his ass.

You get a cookie AND a gold star for describing me perfectly with every single detail.

Oh... Are they the cookies your mommy makes? I love those ones. I also enjoy her pink tacos as well.
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: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by insomaniacal on Wed Jul 21, 2010 10:13 pm
([msg=42397]see Re: C calculator I made:[/msg])

I've read a few of this dude's posts, and yes, he's a defensive dick. However, I'd like to suggest that if you can't figure out how to do something yourself, looking at someone else's code and understanding how it works will do wonders.

You'll also realize why it's important to make your code readable.
It's not who votes that counts, it's who counts the votes
insomaniacal.blog.com
User avatar
insomaniacal
Addict
Addict
 
Posts: 1210
Joined: Sun May 24, 2009 10:21 am
Blog: View Blog (0)


PreviousNext

Return to Idiots' Corner

Who is online

Users browsing this forum: No registered users and 0 guests