Why is there a 31-line writer that there are no identifiers



  • #include <iostream>
    #include<math.h>
    using namespace std;
    
    float numbers(double x, double b, double c)
    {
        cout<<"Input x = ";
        cin >> x;
        cout << "Input b = ";
        cin >> b;
        cout << " Input c = ";
        cin >> c;
    
        float y;
        y = ((2 * x - c) / sqrt(x - b)) + fabs(x - b);
    
        cout << "Answer is " << y;
    
        return y;   
    }
    
    int main()
    {
        int result;
        
        do {
            
            result = numbers(x, b, c);
    
            cout << "x = " << x << endl;
            cout << "b = " << b << endl;
            cout << "c = " << c << endl;
            
            
    
        } while (result <= 0);
        
    }
    


  • Because they're not defined.

    result = numbers(x, b, c);
    

    What is it? xbc? What are they equal? What type do they have?

    Announcement

    float numbers(double x, double b, double c)
    

    acts only within the function, these are the arguments of the function. Outside of her. xbc There's no point.

    And yet... even assuming that it's not true, the arguments given at the end of the function don't change, so the functional values x No one can be removed. cout outside her... ♪

    #include <iostream>
    #include<math.h>
    using namespace std;
    

    double numbers(double &x, double &b, double &c) /// <<< передача по ссылке!!!
    {
    cout<<"Input x = ";
    cin >> x;
    cout << "Input b = ";
    cin >> b;
    cout << " Input c = ";
    cin >> c;

    double y;       /// Используйте везде один тип - или float или double
    y = ((2 * x - c) / sqrt(x - b)) + fabs(x - b);
    
    cout &lt;&lt; "Answer is " &lt;&lt; y;
    
    return y;   
    

    }

    int main()
    {
    double result; /// <<< float/double, не int!!!

    do {
    
        double x, b, c;   /// Объявление переменных     
    
        result = numbers(x, b, c);
    
        cout &lt;&lt; "x = " &lt;&lt; x &lt;&lt; endl;
        cout &lt;&lt; "b = " &lt;&lt; b &lt;&lt; endl;
        cout &lt;&lt; "c = " &lt;&lt; c &lt;&lt; endl;
        
        
    
    } while (result &lt;= 0);
    

    }


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2