Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Needs help in syntax

Posted on 2011-02-23
6
Medium Priority
?
375 Views
Last Modified: 2012-05-11
Hi guys: Can any one please tell me how to raise the power of any number for eg. 2 raise to power 3 = 8

Thanks.

#include <iostream>
using namespace std;

int main()
{
      int number = 0;
        int power1 = 0;
        cout << "Enter Number to raise==>";
        cin >> number;
        cout << "Enter Power==>";
        cin >> power1;
        cout << number^power1;  // syntax error
      system("pause");
      return 0;
}  
0
Comment
Question by:mustish1
  • 3
  • 2
6 Comments
 

Author Comment

by:mustish1
ID: 34966974
I fix the syntax but it still wrong answer

#include <iostream>
using namespace std;

int main()
{
      int number = 0;
        int power1 = 0;
        int result = 0;
        cout << "Enter Number to raise==>";
        cin >> number;
        cout << "Enter Power==>";
        cin >> power1;
        result = number^power1;
        cout << result << endl;
      system("pause");
      return 0;
}  
0
 
LVL 7

Accepted Solution

by:
MrNed earned 2000 total points
ID: 34967000
0
 

Author Comment

by:mustish1
ID: 34967012
Why it gives syntax error
  result = pow(number,power1);

-----------------------
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
      int number = 0;
        int power1 = 0;
        int result = 0;
        cout << "Enter Number to raise==>";
        cin >> number;
        cout << "Enter Power==>";
        cin >> power1;
        result = pow(number,power1);
        cout << result << endl;
      system("pause");
      return 0;
}  
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:MrNed
ID: 34967026
No idea about a syntax error, but check your types. It returns a float/double and the first parameter might need to be casted to a double. Try this:

result = (int)pow((double)number,power1);
0
 

Author Closing Comment

by:mustish1
ID: 34967036
Thanks.
0
 
LVL 8

Expert Comment

by:crysallus
ID: 34967039
It might not know which version of the function to call as your number variable is an int, which doesn't match any of the pow methods exactly. Try:

result = pow((double)number, power1);

which casts the variable number to a double before calling the function, which specifies that it should call that version of the pow function.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question