   Need Help C++ Problem
  Can anybody help me with my problem? I''m having trouble with my calculator program  because my code does''nt work the way I want it  My question is, Why is it that my multiplication() code does''nt do calculations, and my squareroot() does''nt display the correct output?Below is the output of my program. For those who can Help me, I will really appreciate it #include <stdio.h>#include <conio.h>#include <math.h>void addition();void subtraction();void multiplication();void division();void squareroot();double a,b;int c,d;main(void){char ch;printf("choose an operation");printf("\n(a)ddition");    printf("\n(s)ubtraction");printf("\n(m)ultiplication");printf("\n(d)ivision");printf("\nsquare(r)oot");printf("\npress X key to exit\n");  printf("\nchoose operation to perform: ");ch=getchar();switch(ch){  case ''a'':  addition();  break;  case ''s'':  subtraction();  break;  case ''m'':  multiplication();  break;  case ''d'':  division();  break;  case ''r'':  squareroot();  case ''X'':  getch();}    return getche();}void addition(void){printf("\nEnter first number: ");scanf("%d",&a);printf("Enter second number: ");scanf("%d",&b);    a=a+b;printf("The answer is: %d",a);printf("\nPress any key: \n");getche();main();}void subtraction(void){    printf("\nEnter first number: ");scanf("%d",&a);printf("\nEnter second number: ");scanf("%d",&b);    a=a-b;printf("The answer is: %d",a);getche();    main();}void multiplication(void){ printf("\nEnter first number: ");scanf("%i",&a);printf("Enter second number: ");scanf("%i",&b);    a=a*b;printf("\nThe answer is: %i",a);printf("Press any key: ");getche();main(); }void division(void){    printf("\nEnter first number: ");scanf("%d",&a);printf("\nEnter second number: ");scanf("%d",&b);    a= a/b;printf("The answer is: %d",a);getche();main(); }void squareroot(void){double answer;printf("enter a number: ");scanf("%d",&answer);sqrt(answer);printf("the squareroot is %2f",answer);getche();main(); }choose an operation(a)ddition(s)ubtraction(m)ultiplication(d)ivisionsquare(r)ootpress X key to exitchoose operation to perform: mEnter first number: 2Enter second number: 2The answer is: 0Press any key:in my squarerootchoose an operation(a)ddition(s)ubtraction(m)ultiplication(d)ivisionsquare(r)ootpress X key to exitchoose operation to perform: renter a number: 16the squareroot is -92559592117432176000000000000000000000000000000000000000000000.000000   No Signature 
  double a, b;void multiplication(void){ printf("\nEnter first number: ");scanf("%i",a);printf("Enter second number: ");scanf("%i",b);    a*=b;printf("\nThe answer is: %i",a);printf("Press any key: ");getche();main(); }ORdouble *a, *b; //a and b are pointers to doublesvoid multiplication(void){ printf("\nEnter first number: ");scanf("%i",*a); //data pointed to by aprintf("Enter second number: ");scanf("%i",*b); //data pointed to by b    (*a)*=(*b); printf("\nThe answer is: %i",*a);printf("Press any key: ");getche();main(); }To Declare a pointer: type * pointer;To assign a pointer to data: pointer = &dat;To Access data pointed to by a pointer: data = *pointer;Hope this helps.;  try using iostream in the namespace std.  Use cout (See Out) and cin (see in). #include <iostream>#include <math.h>using namespace std;void Mulitply(){int a = 0, b = 0; cout<<"\nEnter first number:";cin>>a;cout<<"\nEnter Second Number:";cin>>b;a *=b;cout<<"\nAnswer = "<<a<<endl;};void SR(){cout<<"\nEnter Number:";float a=0;cin>>a;a = sqrt(a);cout<<endl<<a<<endl;};int main(){Mulitply();SR();return 0;}you can still format it.  you just need to look up iostream flags.  But i think you may be making it harder then it needs to be..   [edited by - MrBeaner on February 13, 2004 2:58:43 AM];  I believe that the problem is in the text parsing... scanf("%i",&a);is looking for an integer, but you defined "a" as double.  everywhere else you are using  scanf("%d",&a);which is correct.In the square root function, sqrt is supposed to return a value, so... sqrt(answer); => answer=sqrt(answer);and then when you print it: printf("the squareroot is %2f",answer);should be  printf("the square root is %2d",answer); lonesockPiranha are people too. ;  Thanks Mashing and Mr. Beaner I'll try that.lonesock I tried switching %i to %d but nothing has change. As a matter of fact I tried switching double to int but the multiplication() does'nt do multiplication at all. But the strange thing is, Addition() and Subtraction() are working fine. Only the Division, the Multiplication and the Squareroot are behaving strange.And one more thing. How do you make a qoute and sourcecode box I tried < sourcecode > < /sourcecode > and < Qoute >< /qoute > but it did'nt work :D    [edited by - makoy on February 13, 2004 6:36:17 AM];  As people have mentioned... using cin/cout objects for your i/o. They will automatically convert to/from text/other types. This means you don't have to worry about all the convertsion symbols mess in printf/scanf. Just look up IO manipulators for how to format it all (if you need). You'll also be doing C++ rather than C in a C++ compiler.EDIT: Also, the C headers for use in C++ should be called cmath, cstdio etc (as opposed to math.h).   [edited by - dmounty on February 13, 2004 7:31:55 AM];quote:Original post by Makoy    And one more thing. How do you make a qoute and sourcecode box I tried < sourcecode > < /sourcecode > and < Qoute >< /qoute > but it did'nt work :DUse: and [ / s o u r c e ]<br><br>with out all the spaces of course.  <br><br><font color="gray" face="Arial Narrow" size="2">"Do not flame people you don't know in a public forum. &#79;nly amateurs do that. Professionals in the industry know they will run into each other over and over. The person you flame this year may the person you want to do business with next year. Don't burn your bridges," <i>(Diana Gruber, http://www.makegames.com/chapt6.html)  </i>  .</font>    <br><br><SPAN CLASS=editedby>[edited by - DIRECTXMEN on February 13, 2004 10:43:30 AM]</SPAN>   ;  Okay thanks a lot guys! That really helped me a alot.  No Signature ;  Don''t call main() in your functions to get back into main! You will end up overflowing the stack. Let your calculation functions return normally and put a loop in your main() function.