Primary Expression Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abilityfun
    New Member
    • Dec 2008
    • 2

    Primary Expression Error

    Please help I don't know what I am doing wrong.

    Code:
    #include <iostream>
    #include <math.h>
    #include <conio.h>
    #include <string.h>
    #include <iomanip>
    
    using namespace std;
    
    double powerOf(double x, int n)
    {
    n++;
    return pow(x,n);
    }
    
    int main()
    {
    int n=0;
    double x=0;
    cout<<"Enter the value you want to know the first ten powers for: ";
    cin>>x;
    for (int i=10;i>0;i--)
    {
    powerOf(int n, double x);
    }
    getch();
    return 0;
    }
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    Code:
    powerOf(int n, double x);
    When you call the function, you don't need to specify the types of the arguments. Also, I think you are passing the arguments in the wrong order. Order matters. You can use
    Code:
    powerOf(x, n);
    but you probably meant to pass it the counter variable in your for loop, i:
    Code:
    powerOf(x, i);
    The variable you pass it can have a different name than the function's parameter, so it's okay to pass i for n.
    And since the function returns a value, you probably meant to do something with the value, like print it:
    Code:
    cout << powerOf(x, i) << endl;
    I hope this is helpful.

    Comment

    • abilityfun
      New Member
      • Dec 2008
      • 2

      #3
      Thanks a lot boxfish it helped :)

      Comment

      Working...