c = getch() version... hehe.. saonz..
PHP Code:
#include<stdio.h>
#include<conio.h>
int add(int, int);
int subtract(int, int);
float divide(int, int);
int multiply(int, int);
void main(void)
{
int a, b, d, e, f;
float g;
char c;
printf("Enter two integers separated by a space: ");
scanf("%d %d", &a, &b);
printf("Select an operation:\n(A) Add\n(S) Subtract\n(D) Divide\n(M) Multiply\n");
printf("Choice: ");
scanf("%c",&c);
c = getch();
if (c=='a' || c=='A')
{
d=add(a, b);
printf("%c\nThe sum of %d and %d is %d\n", c, a, b, d);
}
if (c=='s' || c=='S')
{
e=subtract(a, b);
printf("%c\nThe difference of %d and %d is %d\n", c, a, b, e);
}
if (c=='d' || c=='D')
{
g=divide(a, b);
printf("%c\nThe quotient of %d and %d is %.2f\n", c, a, b, g);
}
if (c=='m' || c=='M')
{
f=multiply(a, b);
printf("%c\nThe product of %d and %d is %d\n", c, a, b, f);
}
getch();
}
int add(int a, int b)
{
return (a+b);
}
int subtract(int a, int b)
{
return (a-b);
}
int multiply(int a, int b)
{
return (a*b);
}
float divide(int a, int b)
{
return ((float)a/b);
}
c = getche() version. lol
PHP Code:
#include<stdio.h>
#include<conio.h>
int add(int, int);
int subtract(int, int);
float divide(int, int);
int multiply(int, int);
void main(void)
{
int a, b, d, e, f;
float g;
char c;
printf("Enter two integers separated by a space: ");
scanf("%d %d", &a, &b);
printf("Select an operation:\n(A) Add\n(S) Subtract\n(D) Divide\n(M) Multiply\n");
printf("Choice: ");
scanf("%c",&c);
c = getche();
if (c=='a' || c=='A')
{
d=add(a, b);
printf("\nThe sum of %d and %d is %d\n", a, b, d);
}
if (c=='s' || c=='S')
{
e=subtract(a, b);
printf("\nThe difference of %d and %d is %d\n", a, b, e);
}
if (c=='d' || c=='D')
{
g=divide(a, b);
printf("\nThe quotient of %d and %d is %.2f\n", a, b, g);
}
if (c=='m' || c=='M')
{
f=multiply(a, b);
printf("\nThe product of %d and %d is %d\n", a, b, f);
}
getch();
}
int add(int a, int b)
{
return (a+b);
}
int subtract(int a, int b)
{
return (a-b);
}
int multiply(int a, int b)
{
return (a*b);
}
float divide(int a, int b)
{
return ((float)a/b);
}