1.11M Members

calculator in c++!check please ..is it working properly

 
1
 
  /*Calculator =========================program*/


     /****************************************************************/
     /*****************************************************************/
           #include <iostream>
          #include <conio>
          #include <stdlib>
    /*****************************************************************/
    /*****************************************************************/

                                float  a[1000];
                                int top=0,i,r;
                                char u;
                                float  input();
                                 float d,p,q,w;
                                 void push(float x);
                                 void get();
               void show(float  arr[]);
 /***********************************************************************/
 /***********************************************************************/
               void main()

               {


                 get();
               getch();}

 /*-------------------------------------------------------------------------*/
 /*-------------------------------------------------------------------------*/

               void get()
              {

                cout<<"\t\tPlease Enter  number\t";
               for(i=0;i<1;i++)

               {
               cin>>a[i];}


               show(a); }


 /*_____________________________________________________________________*/
 /*_____________________________________________________________________*/
               void   show(float  arr[])


               {
                 float  c[33];
                 int v;
                 v=0;

                 for(i=0;i<1;i++)

                 {
                  c[v]=arr[i];v++;
                 }
                  float sum=0;
                  for(i=0;i<1;i++)

                  {
                   sum=sum+c[i];
                  }

                     push(sum);
                     while(1)
                  {
                     cout<<"\n\n";
                    cout<< "chose\n\t\t + \n \t\t - \n \t\t *\n \t\t /\n";
                     cout<<"\t\tpress C for clear screen\n\t\t\Press E for exit\n"<<endl;

                       cin>>u;





                    switch(u)

                    {
                    case '+':
                     d=a[top]+input();
                    cout<<"\t\t\t\t\t\tANS="<<d<<endl;
                    push(d);
                    break;
                    case '-':
                      p=a[top]-input();
                    cout<<"\t\t\t\t\t\tANS="<<p<<endl;
                    push(p);
                    break;
                    case '*':
                     q=a[top]*input();
                    cout<<"\t\t\t\t\t\tANS="<<q<<endl;
                    push(q);
                    break;
                    case '/':
                  w=a[top]/input();
                    cout<<"\t\t\t\t\t\tANS="<<w<<endl;
                    push(w);
                    break;




                    case 'e':
                    exit(0);
                    break;
                    case 'c':
                    clrscr();
                    get();

                    break; }



                    }

               }



/*-----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
                 void push(float  x)

                 {
                   top++;

                   a[top]=x;
                 }
/*______________________________________________________________________________*/
/*______________________________________________________________________________*/

                     float  input()

                    {

                      float  t;
                      cout<<"\t\tPlease Enter  number\t\t";
                      cin>>t;
                      cout<<endl<<endl;

                      return t;

                    }

/*______________________________________________________________________________*/

check it ..is it properly work or not...

 
0
 

No, it's not working properly because it won't compile. Two immediate problems are <conio> and <stdlib> are not a valid headers in any era of C++, and you don't qualify for the std namespace when using <iostream>.

I can't think of a compiler that would accept this code, so I can only assume you didn't compile it. Please don't waste people's time if you're not even willing to build your own code and look at error messages.

Once you fix those problems it will compile when the conio library is fully supported (clrscr() is the usual problematic one), but the code is still hideous and brittle. With perfect input it'll work...after a fashion.

 
0
 

okay but i compile at borland c++ v5 there is compile properly and run complete i say to you just check for exeception hindling ........

 
0
 

i say to you just check for exeception hindling ........

I have no idea what you mean. Your code is broken, your compiler is wrongly accepting it, and nothing will change that. Learn proper C++ instead of depending on broken compiler quirks.

 
-2
 

i am a not expert of c++ but i have little skills in c++.i write,compile and run program of c++ in Borland .there this code is totally correct ...but Thanks for yur feedback....

 
1
 

there this code is totally correct

Then you don't need any help...ever, because you refuse to recognize that your code is WRONG. Have a nice day.

 
0
 

I'm at the begining of my second start in cpp programming but... Deceptikon is right, and he was trying to help you. Only a little research for what he said.

And than...

 for(i=0;i<1;i++)
{
cin>>a[i];}

I see that you declared this globally but you always capture from input to the first element of the array. What you wrote and I quote is equal to cin>>a[0];. You don't need the for statement. Also I don't think that this is what you need. I didn't pass this point.

 
0
 

thanks guys

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: