Untitled

 avatar
unknown
plain_text
a year ago
1.2 kB
5
Indexable
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;
int calculate_y(double x1, double x2, double &y1, double &y2, double &y3 );
//Q : is there a reason why calculate_y returns an integer, and not a double return value ?

int main() {
  double x1,x2,y1,y2,y3; // main doesnt have the arguments
  int ans; // added to find an answer
  
  x1 = 2.0; //have to be defined
  x2 = 6.0; //same
   
  ans =  calculate_y(x1,x2,y1,y2,y3); // its the answer of the function
  
if(ans ==0){   //just in case for an error
    cout << "\nno function";
}else if(ans == 1){ //just in case for an error
    cout << "\nerror in function";
}
   
cout << "\ny1 = " << y1; 
cout << "\ny2 = " << y2;      
cout << "\ny3 = " << y3;


return 0;
}



int calculate_y(double x1, double x2, double &y1, double &y2, double &y3 )
{
    double x3; // have to added
    
    cout << "input the value of x3"; //input
    cin >> x3; //input
    
    y1 = x1 + x2 + x3;
     y2 = sin(x1 * x2);
     
     if( (x1+x2) <= 0.0){ // to counther errors
         return 1; // Q: how come the return 1 comes back to the main function ?
     }
     
     
     y3 = log(x1 + x2);
     
  
     return 0;
}


Editor is loading...
Leave a Comment