Guys, naa miy assignment sa among IT class. Ang question kay:
"Create a pseudocode, flowchart and C program that ask the user 2 integer numbers. The user then enters another character in order to choose which operator to perform: A - addition, S - subtraction, M - multiplication, D- division. Create separate functions for each operation."
Sample run:
Enter two integers: 10,5
Choices:
(A) Addition
(S) Subtraction
(M) Multiplication
(D) Division
Choice: M
The product is 50
Mao ni ang code nga nahimo nako. Nagdiscuss na man mi sugod sa mga control statements, and naa pa mi sa IF controlled loop. The program ran perfectly sa Turbo C diri sa balay namo pero dili siya mu print sa choice and sa answer.
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;
clrscr();
printf("Enter two integers separated by a space:\n");
scanf("%d %d", &a, &b);
printf("Actions:\n(A) Add\n(S) Subtract\n(D) Divide\n(M) Multiply\n");
printf("Choice:\n");
scanf("%c", &c);
if (c=='A')
{
d=add(a, b);
printf("The sum of %d and %d is %d", a, b, d);
getch();
}
if (c=='S')
{
e=subtract(a, b);
printf("The difference of %d and %d is %d", a, b, e);
getch();
}
if (c=='D')
{
float e;
g=divide(a, b);
printf("The quotient of %d and %d is %d", a, b, g);
getch();
}
if (c=='M')
{
f=multiply(a, b);
printf("The product of %d and %d is %d", a, b, f);
getch();
}
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);
}
(PS: I don't know if this is allowed here sa forums. I just don't have anyone to guide me what's wrong with my code.. Check lang ko ni nga thread later sa gabii kay magclase sa ko
![Smiley](images/smilies/smiley.gif)
)
Thanks!