The below code is a calculator in plain C. It does not take into account the operability of bodmas but just one operation at a time. The main thing in the source code below in the scanf which scans the input as number symbol number just as in case of normal calculator. Code: #include<stdio.h> float add(float,float); float sub(float,float); float product(float,float); float divide(float,float); void main() { float n1,n2; char sym,choice; printf("This Program is a program for calculator\n\n"); scanf("%f%c%f",&n1,&sym,&n2); if(sym=='+') printf("\n%f",add(n1,n2)); if(sym=='-') printf("\n%f",sub(n1,n2)); if(sym=='*') printf("\n%f",product(n1,n2)); if(sym=='/') printf("%f",divide(n1,n2)); printf("\nDo you wish to continue[y/n]"); scanf("%s",&choice); if(choice=='y'||choice=='Y') main(); } float add(float m1,float m2) { return(m1+m2); } float sub(float m1,float m2) { return(m1-m2); } float product(float m1,float m2) { return(m1*m2); } float divide(float m1,float m2) { return(m1/m2); }
Verry good. Would you mind joining and writting a tutorial at my forums. SEE MY SIG People hate it when i right a tutorial. I just aint good at telling people how to do something like that. Thanks
I would love to but I see no topics on your forums and so how you know people hate what you write. I also had something similar thinking when I started but thanks to G4EF that made me think otherwise.
i got another option in your program Code: #include <stdio.h><br> #include <conio.h><br> main()<br> {<br> float n1,n2,s,d,p,q;<br> clrscr();<br> printf("\n Enter two nos");<br> scanf("%f%f"&n1,&n2);<br> s=n1+n2;<br> d=n1-n2;<br> p=n1*n2;<br> q=n1/n2;<br> printf("\n Sum %f",s);<br> printf("\n Difference %f",d);<br> printf("\n Product %f",p);<br> printf("\n Quotient %f",q);<br> getch();<br> return(0);<br> }
sorry for that reply....this is the real one Code: #include <stdio.h> #include <conio.h> main() { float n1,n2,s,d,p,q; clrscr(); printf("\n Enter two nos"); scanf("%f%f"&n1,&n2); s=n1+n2 d=n1-n2; p=n1*n2; q=n1/n2; printf("\n Sum %f",s); printf("\n Difference %f",d); printf("\n Product %f",p); printf("\n Quotient %f",q); getch(); return(0); }
what about a supermarket service to calculate prices of goods with fixed prices. with a cashier log in
what about a supermarket service to calculate prices of goods with fixed prices. with a cashier log in
Hy, I begun studying c++ a few days ago and I came across this topic and decided to write a similar program in c++... The code was a bit inspired from the original c calculator Anyway, I would love to read your feedback ^^ Code: #include <cstdlib> #include <cstdio> #include <iostream> using namespace std; double x; double y; double multi(double x, double y); double divi(double x, double y); double sub (double x, double y); double add(double x, double y); int main(int argc, char *argv[]) { char a, z; for(;;) { cin>> x; cin>> z; cin>>y; if (z=='*'){cout<<"=" <<multi (x,y)<< endl;} if (z=='/'){cout<<"=" <<divi (x,y)<< endl;} if (z=='-'){cout<<"=" <<sub (x,y)<< endl;} if (z=='+'){cout<<"=" <<add (x,y)<< endl;} cout<<"Would you like to do another operation? [y/n]"; cin>>a; if (a!='y') {break;} } system("PAUSE"); return EXIT_SUCCESS; } double multi (double x, double y) {return x*y;} double divi (double x, double y) {return x/y;} double sub (double x, double y) {return x-y;} double add (double x, double y) {return x+y;} Cheers!
:worried: hi ,thanks for program ,but this program in the line 25 give error . error : cannot call 'main' from within the program in function main(). please help me . sorry for level low language.
You are using a Cpp compiler and try a C compiler and it would work. For some old TC compiler just renaming the file to .c would compile it for you