Help to fix such errors in the program:

'=': function as left operand
cannot determine which instance of overloaded function "cos" is intended

Program Code:

#include <iostream> #include <math.h> #define PI 3.14159265 using namespace std; int main() { double * x = new double(0.5); double **px = &x; cos = (pow(**px, 3) - pow(**px, 2)); cout << "cos=pow(**px, 3) - pow(**px, 2)" << endl; cout << "cos= " << **px; cout.precision(4); delete *px; system("pause"); return 0; } 

The task itself is:

Using instead of the variable itself a pointer to it, write the program in accordance with the task:
Calculate y = cos | x3-x2 |.

Closed due to the fact that off-topic participants are Vladimir Martyanov , aleksandr barakin , user194374, Alex , pavel 11 December '16 at 16:59 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reasons:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - aleksandr barakin, community spirit, pavel
  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Vladimir Martyanov, Alex
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Where are the mistakes, Katya? - Vladimir Martyanov
  • one
    @ Katya And what does the variable cos mean? The error is that the compiler considers this name as the name of a standard function. - Vlad from Moscow
  • do you need a visual-studio tag here? about the IDE itself is not a word, but can the specialist immediately clear the features of the compiler? but then, probably, and the version must be specified? - 4per
  • one
    @VladD, it's not entirely clear - why would "otherwise it be"? - isnullxbh
  • one
    @VladD, yes, your truth. But you yourself pointed out the conditions under which this stdafx.h appears. I somehow always create an empty project, and have even forgotten how this file looks like) - isnullxbh

2 answers 2

This is double * x = new double(0.5) - too much, you don’t allocate memory for the array. The precision method needs to be executed before you send something to std :: cout, otherwise what's the use of it.

 #include <iostream> #include <math.h> #define PI 3.14159265 using namespace std; int main() { double x = 0.5; double* px = &x; double res = pow( *px, 3 ) - pow( *px, 2 ); cout << "cos=pow(*px, 3) - pow(*px, 2)" << endl; cout.precision(4); cout << "f(x) = cos(0.5) = " << res; return 0; } 

    in line

     cos = (pow(**px, 3) - pow(**px, 2)); 

    mistake. need to

     double res = cos(abs(pow(*px,3)-pow(*px,2))); 

    and at the beginning just announce

     double *px = new double(0.5); 

    and still in cpp you need to write

     #include <cmath> 
    • You can explain why you need to use double *px = new double(0.5); this design? - isnullxbh
    • well, need to use a pointer? the variable itself may not be declared at all, but simply a pointer initialized immediately. - xmikex
    • instead of the variable itself, a pointer to it - as if there should be a variable. As I understand it, this is some kind of very simple task that introduces Katya to pointers)) In general, this is not important, just such constructions are very strange. - isnullxbh
    • Well, in java, objects are created this way, and there objects are essentially pointers. - xmikex