@smarkies: if control statement pa mn gitudlo sa ila... so murag dili pa na pwede sa ila na imong code. I think kanang input jud nimo dapat walay comma.
@smarkies: if control statement pa mn gitudlo sa ila... so murag dili pa na pwede sa ila na imong code. I think kanang input jud nimo dapat walay comma.
murag sakto ko... tungod sa getch... sa last part ra na ibutang imong getch();Enter two integers separated by a space: 15 77
15, 77
Press any key to continue...
pwede rmn butang comma nia sa printf
C rmn xad ni. ang ako ani sauna kai gamay rjd ang code
isud nlng ang opertaion sa imung statement sa if
mfunction rmn jpon na. gamai pa imung codes
dli pd complicated tanawon
wala koy compiler diri...
peru murag mao na ni ang solution
gipang-remove ra nako ang mga getch() except the last one...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); } if (c=='S') { e=subtract(a, b); printf("The difference of %d and %d is %d", a, b, e); } if (c=='D') { float e; g=divide(a, b); printf("The quotient of %d and %d is %d", a, b, g); } if (c=='M') { f=multiply(a, b); printf("The product of %d and %d is %d", 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); }
and sa input... dili ko sure kung pwede ba comma kay wla ko compiler diri... to be sure...seperate it by space na lng jud.
Compiled..
Ddi gihapon na pwedi same ra gihapon sa iyang first post mo exit ang program.
Ari man na sangit pag store sa a and b, then mag store napud sa c.
sige try nako ron dili mag gamit ug do while statement.
Mao man gud ni sabot nako.
The great thing about pseudo-code is that it doesn't have to be correct syntax, it just has to demonstrate the logic of your program. I would often throw together a combination of diagrams/pseudocode before beginning a project.
The program will run inside a do-while loop (it executes the code inside it at least once, since the condition is checked at the end instead of the beginning)
aw u.. sakto.. murag dili diay sa getch()... wla mn diay xa ga getch before gi print niya ang choices.
dara final na dyud ni.
Another code kung for the case. else ifPHP 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);
}
Ouput: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("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();
}
else 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();
}
else 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();
}
else 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();
}
else 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);
}
Addition
Division
Last edited by SmaRkieS; 02-11-2010 at 03:21 PM. Reason: output picture
nag post gud si markcuering ani
i thought gikan ni sa code sa TS... nag conclude dayon ko nga bacn getch...]
Enter two integers separated by a space: 15 77
15, 77
Press any key to continue...
dili mn diay ni code sa TS...
float e; <-- use for what?
printf("The quotient of %d and %d is %d", a, b, g); <-- how you output floating point numbers?
Similar Threads |
|