Solution Found!
Write a functiondouble replace_if_greater(double* p, double x)that replaces the value to
Chapter 7, Problem P7.2(choose chapter or problem)
Write a functiondouble replace_if_greater(double* p, double x)that replaces the value to which p points with x if x is greater. Return the old value towhich p pointed.
Questions & Answers
QUESTION:
Write a functiondouble replace_if_greater(double* p, double x)that replaces the value to which p points with x if x is greater. Return the old value towhich p pointed.
ANSWER:Step 1 of 2
#include <iostream>
using namespace std;
double replace_if_greater(double* p, double x){
if(*p<x){
double temp = *p;
*p = x;
x = temp;
}
cout<<"Value of pointer: "<<*p<<endl;
cout<<"Value of x: "<<x<<endl;
}
int main()
{
double *p;
double x,y;
cout<<"Enter the value of pointer variable and x"<<endl;
cin>>y>>x;
p = &y;
replace_if_greater(p,x);
return 0;
}