@chaosorb: bacn required sa ila mag-gamit ug function. natingala pud ko sa TS nganong redundant iya getch();
@chaosorb: bacn required sa ila mag-gamit ug function. natingala pud ko sa TS nganong redundant iya getch();
"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."
kung pseudocode basihan sayop japon kang smarkies... dapat i-input daan ang integers before choices. hehe
gika ra ni kang smarkies... gi-change lng nako ang order sa pag input... base sa pseudocode...
PHP Code:
#include<stdio.h>
#include<conio.h>
int add(int, int);
int subtract(int, int);
float divide(int, int);
int multiply(int, int);
main(void)
{
int a, b, d, e, f;
float g;
char c;
clrscr();
printf("\nEnter 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);
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')
{
g=divide(a, b);
printf("The quotient of %d and %d is %.2f", 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);
}
mudagan mn japon...
bacn good programming practice lng cguro nga butngan ug variable ang parameters.
Mga bro, salamat kaayo sa inyong pagtabang!I'll see which corrected nga programs nako ang pwede nako magamit.
Ask lang diay ko, unsa ang gamit sa getche()?
(PS: Using katong code with getche() ang naka pa work sa program diay so far.. Pero hadlok man ko mugamit sa getche() nga command oi kay magduda nya ang maestra namo ngano kahibaw ko mugamit ana nga wala man siya nagtudlo ana..)
Last edited by marcdaven; 02-11-2010 at 10:30 PM. Reason: Compiling questions
@xiao: muungot man gihapon siya inig input nako sa desired choice nako.. then gitry nako nga walay getch() sa mga if statements, the same problem man gihapon.. T_T
Code:#include<stdio.h> #include<conio.h> int add(int, int); int subtract(int, int); float divide(int, int); int multiply(int, int); main(void) { int a, b, d, e, f; float g; char c; clrscr(); printf("Select an operation:\n(A) Add\n(S) Subtract\n(D) Divide\n(M) Multiply\n"); printf("Choice: "); scanf("%c",&c); printf("\nEnter two integers separated by a space: "); scanf("%d %d", &a, &b); 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') { g=divide(a, b); printf("The quotient of %d and %d is %.2f", 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); }
@smarkies: Kani nga program hinuon, muwork ni pero pseudocode namo kay dapat maguna ang input of integers before sa choice sa operation.
Sayup ko ani bro..Ang e variable kay para sa subtract diay na nga function.. Dapat wala na diay toy float variable declaration within sa if function sa divide.
Similar Threads |
|