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 AgentDerp on Tue Jul 20, 2010 6:04 pm
([msg=42296]see Re: C calculator I made:[/msg])

Okay, right now I am improving the structure and functionality of the code.
I'll post it when it is finished.
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 msbachman on Tue Jul 20, 2010 6:48 pm
([msg=42300]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?



If you read his follow-up post, you'll see he never claimed to want to show this calculator off:

Constructive criticism: I'm not expert OR intermediate.
I'm just a beginner so the calculator was the best thing I ever made.


And I think why he initially responded as he did (to Goatboy) was to give a rationale for why he didn't make it better, i.e. that he didn't possess the knowledge.

It's not like he flew in here to trash the forum with a post like 'omg u suk fagg0ts chk 0ut ma 1337 c0d3z.' He came across a little defensive in his responses but all in all there's no way this guy belongs in the same forum as that retard 'whitekid'. We should be saving our best flames for people like that, imo. :lol:
"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 Tue Jul 20, 2010 7:32 pm
([msg=42303]see Re: C calculator I made:[/msg])

Meh.
My calculator is acting up.
It's producing 4 errors:
cal.c:21: error: switch quantity not an integer
cal.c:23: error: case label does not reduce to an integer constant
cal.c:33: error: switch quantity not an integer
cal.c:35: error: case label does not reduce to an integer constant

And here's my code:
Code: Select all
#include <stdio.h>

/* Demonstrates a console (text) calculator. */
   
int main(void)
{
    /* Declare the variables. */
    float numb1;
    float numb2;
    float result;
    int oper;
    short i = 0;
   
    /* Start while loop. */
    while (i==0)
    {
   puts("Enter the first decimal number. (0.0 to quit) ");
   scanf("%d", &numb1);
      
        /* Check to see if the user wants to quit. */
   switch (numb1)
   {
      case 0.0:
          /* Exit. */
          break;
   }
      
       puts("Enter the second decimal number. (0.0 to quit) ");
       scanf("%d", &numb2);
      
      /* Check again to see if the user wants to quit. */
      switch (numb1)
      {
          case 0.0:
             /* Exit. */
            break;
         
      }
      
       puts("Enter the ASCII operator (43 (adding), 45 (subtracting), 42 (multiplying), or 47 (dividing). ");
       scanf("%d", &oper);
       switch (oper)
        {
            case 43:
                result = numb1 + numb2;
                printf("The result is %d ", result);
            
            case 45:
             result = numb1 - numb2;
            printf("The result is %d ", result);
            
            case 42:
             result = numb1 * numb2;
            printf("The result is %d ", result);
            
            case 47:
                result = numb1 / numb2;
                printf("The result is %d ", result);
           
            default:
                puts("You have entered a wrong ASCII char.\n");
           
        }
   }
   return 0;
}

What's wrong with it? ;_;
(don't mind the spacing, the forums messed it up again)
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 Tue Jul 20, 2010 8:01 pm
([msg=42307]see Re: C calculator I made:[/msg])

Why the fuck would you help this kid?! He's an asshole. He doesn't want our feedback and there is no way in HELL I am ever going to help this kid out. I say take your errors and get the fuck out of here.
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 Tue Jul 20, 2010 8:10 pm
([msg=42308]see Re: C calculator I made:[/msg])

AgentDerp wrote:Meh.
My calculator is acting up.
It's producing 4 errors:
cal.c:21: error: switch quantity not an integer
cal.c:23: error: case label does not reduce to an integer constant
cal.c:33: error: switch quantity not an integer
cal.c:35: error: case label does not reduce to an integer constant

And here's my code:
Code: Select all
#include <stdio.h>

/* Demonstrates a console (text) calculator. */
   
int main(void)
{
    /* Declare the variables. */
    float numb1;
    float numb2;
    float result;
    int oper;
    short i = 0;
   
    /* Start while loop. */
    while (i==0)
    {
   puts("Enter the first decimal number. (0.0 to quit) ");
   scanf("%d", &numb1);
      
        /* Check to see if the user wants to quit. */
   switch (numb1)
   {
      case 0.0:
          /* Exit. */
          break;
   }
      
       puts("Enter the second decimal number. (0.0 to quit) ");
       scanf("%d", &numb2);
      
      /* Check again to see if the user wants to quit. */
      switch (numb1)
      {
          case 0.0:
             /* Exit. */
            break;
         
      }
      
       puts("Enter the ASCII operator (43 (adding), 45 (subtracting), 42 (multiplying), or 47 (dividing). ");
       scanf("%d", &oper);
       switch (oper)
        {
            case 43:
                result = numb1 + numb2;
                printf("The result is %d ", result);
            
            case 45:
             result = numb1 - numb2;
            printf("The result is %d ", result);
            
            case 42:
             result = numb1 * numb2;
            printf("The result is %d ", result);
            
            case 47:
                result = numb1 / numb2;
                printf("The result is %d ", result);
           
            default:
                puts("You have entered a wrong ASCII char.\n");
           
        }
   }
   return 0;
}

What's wrong with it? ;_;
(don't mind the spacing, the forums messed it up again)


My C is rusty but I'm pretty sure you can't use switch with integers.
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 AgentDerp on Tue Jul 20, 2010 8:15 pm
([msg=42310]see Re: C calculator I made:[/msg])

sanddbox wrote:
AgentDerp wrote:Meh.
My calculator is acting up.
It's producing 4 errors:
cal.c:21: error: switch quantity not an integer
cal.c:23: error: case label does not reduce to an integer constant
cal.c:33: error: switch quantity not an integer
cal.c:35: error: case label does not reduce to an integer constant

And here's my code:
Code: Select all
#include <stdio.h>

/* Demonstrates a console (text) calculator. */
   
int main(void)
{
    /* Declare the variables. */
    float numb1;
    float numb2;
    float result;
    int oper;
    short i = 0;
   
    /* Start while loop. */
    while (i==0)
    {
   puts("Enter the first decimal number. (0.0 to quit) ");
   scanf("%d", &numb1);
      
        /* Check to see if the user wants to quit. */
   switch (numb1)
   {
      case 0.0:
          /* Exit. */
          break;
   }
      
       puts("Enter the second decimal number. (0.0 to quit) ");
       scanf("%d", &numb2);
      
      /* Check again to see if the user wants to quit. */
      switch (numb1)
      {
          case 0.0:
             /* Exit. */
            break;
         
      }
      
       puts("Enter the ASCII operator (43 (adding), 45 (subtracting), 42 (multiplying), or 47 (dividing). ");
       scanf("%d", &oper);
       switch (oper)
        {
            case 43:
                result = numb1 + numb2;
                printf("The result is %d ", result);
            
            case 45:
             result = numb1 - numb2;
            printf("The result is %d ", result);
            
            case 42:
             result = numb1 * numb2;
            printf("The result is %d ", result);
            
            case 47:
                result = numb1 / numb2;
                printf("The result is %d ", result);
           
            default:
                puts("You have entered a wrong ASCII char.\n");
           
        }
   }
   return 0;
}

What's wrong with it? ;_;
(don't mind the spacing, the forums messed it up again)


My C is rusty but I'm pretty sure you can't use switch with integers.

It says "switch quantity not an integer"
Which probably mean you HAVE to put an integer in.
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 8:22 pm
([msg=42313]see Re: C calculator I made:[/msg])

AgentDerp wrote:
sanddbox wrote:
AgentDerp wrote:Meh.
My calculator is acting up.
It's producing 4 errors:
cal.c:21: error: switch quantity not an integer
cal.c:23: error: case label does not reduce to an integer constant
cal.c:33: error: switch quantity not an integer
cal.c:35: error: case label does not reduce to an integer constant

And here's my code:
Code: Select all
#include <stdio.h>

/* Demonstrates a console (text) calculator. */
   
int main(void)
{
    /* Declare the variables. */
    float numb1;
    float numb2;
    float result;
    int oper;
    short i = 0;
   
    /* Start while loop. */
    while (i==0)
    {
   puts("Enter the first decimal number. (0.0 to quit) ");
   scanf("%d", &numb1);
      
        /* Check to see if the user wants to quit. */
   switch (numb1)
   {
      case 0.0:
          /* Exit. */
          break;
   }
      
       puts("Enter the second decimal number. (0.0 to quit) ");
       scanf("%d", &numb2);
      
      /* Check again to see if the user wants to quit. */
      switch (numb1)
      {
          case 0.0:
             /* Exit. */
            break;
         
      }
      
       puts("Enter the ASCII operator (43 (adding), 45 (subtracting), 42 (multiplying), or 47 (dividing). ");
       scanf("%d", &oper);
       switch (oper)
        {
            case 43:
                result = numb1 + numb2;
                printf("The result is %d ", result);
            
            case 45:
             result = numb1 - numb2;
            printf("The result is %d ", result);
            
            case 42:
             result = numb1 * numb2;
            printf("The result is %d ", result);
            
            case 47:
                result = numb1 / numb2;
                printf("The result is %d ", result);
           
            default:
                puts("You have entered a wrong ASCII char.\n");
           
        }
   }
   return 0;
}

What's wrong with it? ;_;
(don't mind the spacing, the forums messed it up again)


My C is rusty but I'm pretty sure you can't use switch with integers.

It says "switch quantity not an integer"
Which probably mean you HAVE to put an integer in.


Sorry, that's what I meant. You can't use non-integers :P
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 Assassian360 on Tue Jul 20, 2010 9:16 pm
([msg=42320]see Re: C calculator I made:[/msg])

AgentDerp wrote:Meh.
My calculator is acting up.
It's producing 4 errors:
cal.c:21: error: switch quantity not an integer
cal.c:23: error: case label does not reduce to an integer constant
cal.c:33: error: switch quantity not an integer
cal.c:35: error: case label does not reduce to an integer constant

And here's my code:
Code: Select all
#include <stdio.h>

/* Demonstrates a console (text) calculator. */
   
int main(void)
{
    /* Declare the variables. */
    float numb1;
    float numb2;
    float result;
    int oper;
    short i = 0;
   
    /* Start while loop. */
    while (i==0)
    {
   puts("Enter the first decimal number. (0.0 to quit) ");
   scanf("%d", &numb1);
      
        /* Check to see if the user wants to quit. */
   switch (numb1)
   {
      case 0.0:
          /* Exit. */
          break;
   }
      
       puts("Enter the second decimal number. (0.0 to quit) ");
       scanf("%d", &numb2);
      
      /* Check again to see if the user wants to quit. */
      switch (numb1)
      {
          case 0.0:
             /* Exit. */
            break;
         
      }
      
       puts("Enter the ASCII operator (43 (adding), 45 (subtracting), 42 (multiplying), or 47 (dividing). ");
       scanf("%d", &oper);
       switch (oper)
        {
            case 43:
                result = numb1 + numb2;
                printf("The result is %d ", result);
            
            case 45:
             result = numb1 - numb2;
            printf("The result is %d ", result);
            
            case 42:
             result = numb1 * numb2;
            printf("The result is %d ", result);
            
            case 47:
                result = numb1 / numb2;
                printf("The result is %d ", result);
           
            default:
                puts("You have entered a wrong ASCII char.\n");
           
        }
   }
   return 0;
}

What's wrong with it? ;_;
(don't mind the spacing, the forums messed it up again)


So far the guys have just said you are allowed Integers. You can also have char types as the method of switching. (this is because they have unique integer numbers representing them)

eg:
Code: Select all
char operator = '*';
switch(operator)
{
        case '+':
                  // deal with +
                  break;
        case '-':
                 // deal with -
                 break;
        case 'A':
                // not for the calculator but to demonstrate that you can use letters etc
                break;
        case '*':
                // deal with *
        ....... // etc
}


Switch statements should really be used when you have a number of different options to actually choose from. The first few switch statements you have put in early on deal with single cases (where you seem to be checking for exiting). These should be checked using IF statements instead. I may be wrong, but I would assume you can type in 0 or 0.0 in your input and it would still detect it correctly (same with any other number) which also means if you are doing a direct comparison you can just write it as: if(numb1 == 0) for example.

You seem to want an infinite loop, hence have gone for the while(i == 0). Rather than dedicating a variable that is never going to change, you could just write while(true) or for(;;) and it will make your loop infinite till the user chooses to quit.

Hope this helps :)
Assassian360
Poster
Poster
 
Posts: 135
Joined: Sat Jun 26, 2010 1:37 am
Blog: View Blog (0)


Re: C calculator I made:

Post by Goatboy on Wed Jul 21, 2010 12:21 am
([msg=42326]see Re: C calculator I made:[/msg])

We should not be helping this kid. He has made it VERY clear in numerous posts that he does not want criticism, nor does he plan on improving the code. If he wants help, he needs to ask for it politely, sans the attitude.
Assume that everything I say is or could be a lie.
1UHQ15HqBRZFykqx7mKHpYroxanLjJcUk
User avatar
Goatboy
Expert
Expert
 
Posts: 2823
Joined: Mon Jul 07, 2008 9:35 pm
Blog: View Blog (0)


Re: C calculator I made:

Post by fashizzlepop on Wed Jul 21, 2010 12:41 am
([msg=42330]see Re: C calculator I made:[/msg])

I couldn't agree more goatboy (as you've probably noticed). This should be locked. And I am glad it was moved to IC.
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)


PreviousNext

Return to Idiots' Corner

Who is online

Users browsing this forum: No registered users and 0 guests

cron