اذهب إلى المحتوى
  • 0

المساعدة في حل سؤال ++C

حمامه السلام

السؤال

Write a c++ function name it isfloat that checks if number is float or not the correct float number comes in any of following.  forms   -0.584  .258 -.894  0.156  + 0.1253  ask the user to enter two float numbers (check them using isfloet function that you wrote above ) and your program should print the sum and multiplication of the two float numbers    .      

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 1

مرحباً بك @Manar Ramadan.

هذا هو الحلل :


#include <iostream>

using namespace std;

bool isfloat(float f1, float f2)
{
    
    // المنطق : 
    // عليمة طرح الرقم مع ذاته من غير كسور و المقارنة بعد ذلك إذا كان أكبر من صفر
    // و نسترجع قيمة منطقية على حسب الحال
    if( abs(f1-int(f1) > 0 && abs(f2-int(f2) > 0 ))){
        return true;
    }else{
        return false;
    }
  
}

int main()
{
    
    float f1,f2;
    
    // المستخدم يكتب الأرقام
    cout << "Float 1 : ";
    cin >> f1;
    cout << "Float 2 : ";
    cin >> f2;

    //متغير القيمة المنطقية
    bool isFloat = isfloat(f1,f2);
    
    if (isFloat){
        //floats إذا كان الرقمان
        cout << "They are Floats" << "\n";
        
        cout << "Multiply : ";
        cout << f1 * f2 << "\n";
        
        cout << "Addition : ";
        cout << f1 + f2 << "\n";
        
    }else{
        //floats إذا لم يكن الرقمان
        cout << "Both or one of them is Integars" << "\n";
    }
    
    return 0;
}

شكراً لك.

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...