Solved

Needs help in syntax

Posted on 2011-02-23
6
350 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This video teaches viewers about errors in exception handling.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

810 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