1

I know my work is sloppy, this is my 4th assignment in this class. Any help would be appreciated, thank you.

double  getPrincipal(0);
double  getRate(0);
double  getYears(0);
double  computeAmount(double getPrincipal, double getRate, double getYears);
double  displayAmount(double principal, double rate, double years, double amount);

cout << "what is the principal ammount?" << endl;
cin >> getPrincipal;

cout << "What is the percentage rate?" << endl;
cin >> getRate;

cout << "Over how many years will the money stay in the bank?" << endl;
cin >> getYears;  

computeAmount = pow((1 + getRate / 100),getYears); // This is where i got the error
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
user3361763
  • 7
  • 1
  • 3

5 Answers5

3

You are messing up functions with variables by trying to assign a value to a function.

double  computeAmount(double getPrincipal, double getRate, double getYears);

By this line, you declare computeAmount() to be a function who takes 3 doubles as its parameters and return a double.

But, in this line,

computeAmount = pow((1 + getRate / 100),getYears);

You're trying to use it as a variable.

Depends on what your purpose is, you may want to change one of these two lines. For example, you can delete the first line, and change the second line to:

double computeAmount = pow((1 + getRate / 100),getYears);
herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
  • _'You can't assign a value to a function.'_ Well, actually you can: `virtual void foo() = 0;` – πάντα ῥεῖ Feb 27 '14 at 18:44
  • 1
    @πάνταῥεῖ That is not an assignment, but a syntactical way of specifying a pure virtual function. – Zac Howland Feb 27 '14 at 18:48
  • @ZacHowland You can actually use values other than `0` (and there are even reasonable use cases for this). – πάντα ῥεῖ Feb 27 '14 at 18:52
  • 1
    @πάνταῥεῖ If you mean `= delete` or `= default`, yes, but again, those are not assignment, but simply syntax for [stating information about the function](http://stackoverflow.com/a/2156723/529761). You cannot write `virtual void foo() = 1;` - it will not compile. – Zac Howland Feb 27 '14 at 18:57
  • @ZacHowland No I meant s.th. like `virtual void foo() = 0x00000f24;`. You can use it to bind certain ROM addresses on bare metal environments. Seen that, been there ... May be a compiler specific extension though. – πάντα ῥεῖ Feb 27 '14 at 19:00
  • 1
    @πάνταῥεῖ That is not [standard compliant](http://ideone.com/Cgy5PD). The `= 0` notation is not *assigning* the function to 0, it is stating the function is not there. Stroustrup went with that syntax instead of trying to fight with people over adding a new keyword. In effect, `= 0` (when used in this context) is really just a keyword stating the function is a pure virtual function (and prior to C++11, `0` was the only valid token after the `=`. C++11 added `default` and `delete` to the list). – Zac Howland Feb 27 '14 at 19:02
1

As the compiler is trying to tell you, you can't assign a variable to a function

If you want that to be a function, define it & call it.

If you want it to be a variable, declare it as a variable.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
1

computeAmount is the name of a function you defined that returns a double and takes 3 double parameters. pow returns a double.

Change that line to

double computedAmount = pow((1 + getRate) / 100, getYears);
       ^^^^^^^^^^^^^^ -- notice this is no longer the function name, but a new variable
Zac Howland
  • 15,777
  • 1
  • 26
  • 42
1

You declared name computeAmount as a function name

double  computeAmount(double getPrincipal, double getRate, double getYears);

So this statement

computeAmount = pow((1 + getRate / 100),getYears);

has no sense. As computeAmount is a function name then in the espression above it is converted to pointer to function and you are trying to assign some double value returned by function pow to this pointer.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
1

computeAmount is declared as a function, but used on the left-hand side of '=' operator. Solution: Re-declare computeAmount as just a double:

double computeAmount;
RamblinRose
  • 172
  • 6