C++ Programming

Write a Function that Passes two Temperature by Reference

Write a Function that Passes two Temperature by Reference and Saves the Larger of the Two Number to Hundred by Using Return by Reference.

Source Code

#include<iostream.h>

#include<conio.h>

 float t1,t2;

void main()

{

  float &itemp(float &,float&);

 cout<<"Enter 1 temperature:"<<endl;

 cin>>t1;

 cout<<"Enter 2 temperature:"<<endl;

 cin>>t2;

 if(t1==t2)

 cout<<"Equal"<<endl;

 else

 {itemp(t1,t2)=100;

 if(t1==100)

 cout<<"Temperature 1is graeter"<<endl;

 else

 cout<<"Temperature 2 is larger"<<endl;

 }

  getch();

 }




float &itemp(float &a,float &b)

{

if(a>b)

return a;

else

return b;

}
Back to top button