*hmm..I can't seem to make this code to work,it always bypasses reading the "operation" and doesn't read it.I would apperciate it ,if you could help me out..thnx in advance =)
**program basically reads 2 float numbers from the user and a character '*', '-' , '/', '+' and does one of these operations and prints out the result..and also goes into a loop~
***operations is a subprogram..I think that covers it all..I know 1st post shouldn't be a question..sorry & thnx ..
Sample example ( user input in bold )
Enter first number 3.4
Enter second number 2.7
Enter operation +
The result of 3.4 + 2.7 = 6.1
Another operation ? ( Y/N ) Y
Enter first number 1.2
Enter second number 4.0
Enter operation /
The result of 1.2 / 4.0 = 0.3
Another operation ? ( Y/N) N
Code:#include <stdio.h> #include <conio.h> void math (float a, float b,char f) { float result; if ( f=='+') result = a+b; else if (f=='-') result = a-b; else if (f=='*') result = a*b; else if (f=='/') result = a/b; esle print("wrong input"); printf("result = %f",result); } void main() { float x,y; char operation,answer; do{ printf("enter 1st number\n"); scanf("%f",&x); printf("enter 2nd number\n"); scanf("%f",&y); printf("enter operation \n"); scanf("%c",&operation); math(x,y,operation); printf("Do it again?\n"); scanf("%c",&answer); }while((answer=='y')||(answer=='Y')); getch(); }



LinkBack URL
About LinkBacks


