Solved

Needs help in syntax

Posted on 2011-02-23
6
352 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 500 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
Technology Partners: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
simplest php form 3 85
ASP/VB email question 4 62
how i declare an array which contains email address corresponding to names. 2 62
learn programming 8 68
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 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