
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?
Constructive criticism: I'm not expert OR intermediate.
I'm just a beginner so the calculator was the best thing I ever made.

#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;
}


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)


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.

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.


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



Users browsing this forum: No registered users and 0 guests