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)

Get Unlimited 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.

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;

}

 

Add to cart


Study Tools You Might Need

Not The Solution You Need? Search for Your Answer Here:

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back