Hello.
I wrote this program to test my (very basic, limited) understanding of C++ thus far. What I got is this:
The problem here is the line txy = mult(*xp, *yp) ;. I get an error stating that I'm not allowed to compare pointers with integers. However as far as I understand using a pointer in this manner (*xp) should be just like using the original integer no?Code:#include <iostream> using namespace std; int mult ( int x, int y ); int main() { int x; int *xp = new int; int y; int *yp = new int; int txy ; int ran ; xp = &x; yp = &y; ran = rand() ; cout<<"Write num\n"; cin>>x; cin.ignore(); cout<<"The num you wrote is "<<*xp<<"\n"; cout<<"Write num\n"; cin>>y; cin.ignore(); cout<<"The num you wrote is "<<*yp<<"\n"; txy = mult(x, y) ; if (txy>ran) { cout<<txy<<">"<<ran ; } else { cout<<txy<<"<"<<ran ; } cin.get() ; return 0 ; delete xp ; delete yp ; xp = 0 ; yp = 0 ; } int mult ( int x, int y ) { return x * y; }
Thanks for any answer!