Just editing my calculator and looking at what functions math.h had and i came across pow,

My program compiles and things like that so no error but if I'm not mistaken the answer is wrong.

6 ^ 1 = 6X6? = 36 (IS THAT CORRECT??)

JUST IN MY PROGRAM IF I USE 6^1 IT GIVES ME 1

#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdio.h>

using namespace std;

#define PI 3.14159265

void binary(int);

int main()
{
    system("TITLE My Calculator Program.");
    system("COLOR C");
     
    double firstNumber, secondNumber;
    double resultSqrt, resultSin, resultCos, resultTan, resultBinary;
    double resultPower;
    char operation, boolSqrt; 
    
    cout << " *****************************************" << endl;;
    cout << "  Kizzop Productions - Simple Calculator!" << endl;;
    cout << " *****************************************\n\n"; 
    
    cout << "  OPERATORS : +, -, *, /, !, ^, S, C, T, B" << endl;
    cout << "\n";
    
    cout << "  + = ADD\n  - = SUBTRACT\n  * = Multiplication\n  ";
    cout << "/ = Division\n  ! = SQAURE ROOT\n  ^ = POWER\n  S = SIN\n  ";
    cout << "C = COS\n  T = TAN\n  B = BINARY\n";
    
    cout << " \n ************************************************" << endl;
    cout << "  NOTE : YOU CAN USE X AND x FOR MULTIPLICATION!" << endl;
    cout << " ************************************************\n\n";    
       
    cout << "\n ENTER FIRST NUMBER  : ";
    cin  >> firstNumber;

    cout << "\n ENTER OPERATOR SIGN : ";
    cin  >> operation;
    
    resultSqrt = sqrt (firstNumber);
    
    resultPower = pow (firstNumber, secondNumber);
    
    //resultBinary = binary (firstNumber);
    
    resultSin = sin (firstNumber*PI/180);
    
    resultCos = cos (firstNumber*PI/180);
    
    resultTan = tan (firstNumber*PI/180);
    
         switch(operation)
         {
                          case '+':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber + secondNumber);
                          break;
                          
                          case '-':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber - secondNumber);
                          break;
                          
                          case '*':
                          case 'x':
                          case 'X':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber * secondNumber);
                          break;
                          
                          case '/':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber / secondNumber);
                          break;
                          
                          case '!':
                          cout << "\n ANSWER = " << resultSqrt;
                          break;
                          
                          case '^':
                          cout << "\n TO THE POWER OF : ";
                          cin  >> secondNumber;
                          cout << "\n ANSWER = " << resultPower;
                          break;
                          
                          case 'S':
                          case 's':
                          cout << "\n ANSWER = " << resultSin;
                          break;
                          
                          case 'C':
                          case 'c':
                          cout << "\n ANSWER = " << resultCos;
                          break;
                          
                          case 'T':
                          case 't':
                          cout << "\n ANSWER = " << resultTan;
                          break;
                          
                          case 'B':
                          case 'b':
                          cout << "\n ANSWER = " << resultBinary;
                          break;
                          
                          default:
                          cout << "\n WRONG MATHEMATICAL OPERATOR!";
                          break;
                          
         }
                          system("PAUSE > nul");
         }
            
/*
void binary(int number) 
{
     int remainder;
     
     if( number <= 1 )
     {
         cout << number;
         
         return;
     }
     
     remainder = number % 2;
     binary (number >> 1);
     cout << remainder;
     
}
*/

>>6 ^ 1 = 6X6? = 36 (IS THAT CORRECT??)
No, that is not corrtect. 6 ^ 2 is 6 x 6.
6 ^ 1 = 6

you can use a calculator to verify the math

And 6^0=1

Oops sorry.

I recompiled my program and went 6 ^ 2, and the answer was still one..

HELP?

Line 45

resultPower = pow (firstNumber, secondNumber);

Either initialize secondNumber or get its value using cin

I just ran your code for power and it runs fine. In most cases you are using cin after you input the operator and then perform the required operation. But in this case either input secondNumber before line 45 or use the pow() function in the 'case' for ^ after you have taken 'secondNumber'

Oh, I've said to use pow before the user has entered the value, thank you hammerhead!

#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdio.h>

using namespace std;

#define PI 3.14159265

/*void binary(int);*/

int main()
{
    system("TITLE My Calculator Program.");
    system("COLOR C");
     
    double firstNumber, secondNumber;
    double resultSqrt, resultSin, resultCos, resultTan, resultBinary;
    double resultPower;
    char operation, boolSqrt; 
    
    cout << " *****************************************" << endl;;
    cout << "  Kizzop Productions - Simple Calculator!" << endl;;
    cout << " *****************************************\n\n"; 
    
    cout << "  OPERATORS : +, -, *, /, !, ^, S, C, T, B" << endl;
    cout << "\n";
    
    cout << "  + = ADD\n  - = SUBTRACT\n  * = Multiplication\n  ";
    cout << "/ = Division\n  ! = SQAURE ROOT\n  ^ = POWER\n  S = SIN\n  ";
    cout << "C = COS\n  T = TAN\n  B = BINARY\n";
    
    cout << " \n ************************************************" << endl;
    cout << "  NOTE : YOU CAN USE X AND x FOR MULTIPLICATION!" << endl;
    cout << " ************************************************\n\n";    
       
    cout << "\n ENTER FIRST NUMBER  : ";
    cin  >> firstNumber;

    cout << "\n ENTER OPERATOR SIGN : ";
    cin  >> operation;
    
    resultSqrt = sqrt (firstNumber);
        
    //resultBinary = binary (firstNumber);
    
    resultSin = sin (firstNumber*PI/180);
    
    resultCos = cos (firstNumber*PI/180);
    
    resultTan = tan (firstNumber*PI/180);
    
         switch(operation)
         {
                          case '+':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber + secondNumber);
                          break;
                          
                          case '-':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber - secondNumber);
                          break;
                          
                          case '*':
                          case 'x':
                          case 'X':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber * secondNumber);
                          break;
                          
                          case '/':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber / secondNumber);
                          break;
                          
                          case '!':
                          cout << "\n ANSWER = " << resultSqrt;
                          break;
                          
                          case '^':
                          cout << "\n TO THE POWER OF : ";
                          cin  >> secondNumber;
                          
                          resultPower = pow (firstNumber, secondNumber);6
                          
                          cout << "\n ANSWER = " << resultPower;
                          break;
                          
                          case 'S':
                          case 's':
                          cout << "\n ANSWER = " << resultSin;
                          break;
                          
                          case 'C':
                          case 'c':
                          cout << "\n ANSWER = " << resultCos;
                          break;
                          
                          case 'T':
                          case 't':
                          cout << "\n ANSWER = " << resultTan;
                          break;
                          
                          case 'B':
                          case 'b':
                          cout << "\n ANSWER = " << resultBinary;
                          break;
                          
                          default:
                          cout << "\n WRONG MATHEMATICAL OPERATOR!";
                          break;
                          
         }
                          system("PAUSE > nul");
         }
            
/*
void binary(int number) 
{
     int remainder;
     
     if( number <= 1 )
     {
         cout << number;
         
         return;
     }
     
     remainder = number % 2;
     binary (number >> 1);
     cout << remainder;
     
}
*/

WOO, POWER IS WORKING!

NOW JUST TO GET THE BINARY WORKING =/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.