hello!
i am a brand new user to this site ihope that my experence with this site would be better than previous ones, i am studying BS(computer science), recently i had trouble with a program that ihave made well that thing is that its is complete and working as well but there are problems with it i am sending the program as .cpp file i hope people at dani web will help me in correcting the program most of the problem is with the part where there is modulus and factorial function. :?:

Attachments
#include<iostream.h>
#include<stdlib.h>
#include<conio.c>
int Add();
int Mod();
int Mul();
int Ftrl();
int Pow();
 main()
 {
  char p;
   cout<<"\tmenu\n";
   cout<<"\t addition : A \n";
   cout<<"\t mod : O\n";
   cout<<"\t multiplication : M \n";
   cout<<"\t factorial : F \n";
   cout<<"\t power : p \n";
   
  
   cout<<"\t Plz enter option \n";
   cin>>p;
  
  switch (p)
  {
     case 'A':
     case 'a':
        cout<<"the result is:\t"<<Add();
        
     case 'O':
     case 'o':
        cout<<"the result is:\t"<<Mod();
        
     case 'F':
     case 'f':
          cout<<"the result is:\t"<<Ftrl();
        
     case 'M':
     case 'm':
        cout<<"the result is:\t"<<Mul();
        
     case 'P':
     case 'p':
        cout<<"the result is:\t"<<Pow();
            
     case 'Q':
     case 'q':
        cout<<"khudahafiz";
                
        }
 system("pause");
  
 }
 
        int Add()
        {  int r,a,b;
               cout<<"nter 1st no\t";
               cin>>a;       
                cout<<"nter 2nd no\t";
               cin>>b; 
  
           r=a+b;
           return r;
         }    
  
int Mul()
        {  int r,a,b;
               cout<<"nter 1st no\t";
               cin>>a;       
                cout<<"nter 2nd no\t";
               cin>>b; 
  
           r=a*b;
           return r;
         }    
int Ftrl()
        {     int a,b,k; long c=1;      
               cout<<"nter 1st no\t";
               cin>>a; 
               for( b=a;b>0;b--)
               {   
                 c=c*b;
                             
                 }
                 cout<<"result of 1stno :\t"<<c; 
                 
                 
                 int z,d; long e=1;      
               cout<<"nter 2nd no o\t";
               cin>>d; 
               for( z=d;z>0;z--)
               {   
                 e=e*z;
                                  
                 }
                 cout<<"\nresult of 2nd no:\t"<<e;
                 k=e+c;
                 return k;                 
                 }
           
         int Mod()
        {  int r,a,b;
               cout<<"nter 1st no\t";
               cin>>a;       
                cout<<"nter 2nd no\t";
               cin>>b; 
  
          r%=a/b ;
           return r;
         }    
    
       int Pow()
        {  int i,a,b;
               cout<<"nter 1st no\t";
               cin>>a;       
                cout<<"nter 2nd no\t:";
               cin>>b; 
  
           i=a^b;
           return i;
         }

What are you trying to do with those two functions? It's clearly not a simple factorial or modulo calculation, so unless you describe what the problem is, we can't help. Though I can tell you right now that your power function isn't going to work like you expect.

>i=a^b;
^ is the bitwise exclusive OR operator, not the power operator. C++ doesn't have such an operator.

can anyone tell me what is the syntx for power in c++ as well as factorial and modulus because i am at a begginers stage.

Power is a function declared in the <cmath> header:

#include <cmath>
#include <iostream>

using namespace std;

int main()
{
  cout<< pow ( 2, 4 ) <<endl;
}

Modulus does have an operator (%), but it only works for integer values. For floating-point, you need to use the fmod function declared in the <cmath> header.

N! is easy to calculate:

#include <iostream>

using namespace std;

int factorial ( int n )
{
  int r = n;

  while ( --n > 0 )
    r *= n;

  return r;
}

int main()
{
  cout<< factorial ( 5 ) <<endl;
}
This article has been dead for over six months. Start a new discussion instead.