Ektb Code - اكتب كود
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

اذهب الى الأسفل
ibrahim sherif mohamed
ibrahim sherif mohamed
مبرمج جديد
مبرمج جديد
Posts : 9
Points : 1340
Reputation : 0
Join date : 11/08/2020

[تم الحل]a functions doesn't work properly Empty [تم الحل]a functions doesn't work properly

الثلاثاء أغسطس 11, 2020 11:37 pm
الكود:
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double PeriodicPayment (double l, double r, double m, double t);
double unpaidBalance (double m, double t, double k);


int main()
{
    double l, r, m, t, k;
    char ch;
    do
    {
    cout << fixed << showpoint << setprecision(2)
        << "enter the loan: " << endl;
    cin >> l;
    cout << endl << "enter the interest rate: " << endl;
    cin >> r;
    cout << endl << "enter the number of payments in a year: " << endl;
    cin >> m;
    cout << endl << "enter the number of years: " << endl;
    cin >> t;
    cout << endl << "enter a certain payment to get the unpaid balance: " << endl;
    cin >> k;
    cout << endl << "the periodic payment is " << PeriodicPayment(l, r, m, t) << endl
        << "the unpaid balance is " << unpaidBalance(m, t, k) << endl
        << "press any key to continue or 'n' to end ";
    cin >> ch;
    }
    while (ch != 'n');
    return 0;
}

double i;
double periodPay;

double PeriodicPayment (double l, double r, double m, double t)
{
    i = r / m;
    periodPay = l * i / (1 - pow(1 + i, - m * t));

    return periodPay;
}

double unpaidBalance (double m, double t, double k)
{
    double remainBalance = periodPay * ((1 - pow(1 + i, - m * t - k )) / i);
    return remainBalance;
}
Ektb Code
Ektb Code

Posts : 54
Points : 1584
Reputation : 11
Join date : 05/05/2020
https://ektbcode.ahlamontada.com

[تم الحل]a functions doesn't work properly Empty رد: [تم الحل]a functions doesn't work properly

الأحد أغسطس 16, 2020 11:34 am
ايه المشكلة بالظبط هنا؟
ibrahim sherif mohamed
ibrahim sherif mohamed
مبرمج جديد
مبرمج جديد
Posts : 9
Points : 1340
Reputation : 0
Join date : 11/08/2020

[تم الحل]a functions doesn't work properly Empty رد: [تم الحل]a functions doesn't work properly

الأحد أغسطس 16, 2020 5:51 pm
اخر فنكشن مش بتطلع الناتج صح
Ektb Code
Ektb Code

Posts : 54
Points : 1584
Reputation : 11
Join date : 05/05/2020
https://ektbcode.ahlamontada.com

[تم الحل]a functions doesn't work properly Empty رد: [تم الحل]a functions doesn't work properly

الخميس أغسطس 20, 2020 8:37 pm
لان المتغير periodPay لما استخدمته في unpaidBalance كان بدون قيمة لازم تنادي عليه في الmain وتخليه يستقبل الناتج اللي هيرجع من PeriodicPayment

الكود:
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double PeriodicPayment (double l, double r, double m, double t);
double unpaidBalance (double m, double t, double k);

double i;
double periodPay;

int main()
{
    double l, r, m, t, k;
    char ch;
    do
    {
    cout << fixed << showpoint << setprecision(2)
        << "enter the loan: " << endl;
    cin >> l;
    cout << endl << "enter the interest rate: " << endl;
    cin >> r;
    cout << endl << "enter the number of payments in a year: " << endl;
    cin >> m;
    cout << endl << "enter the number of years: " << endl;
    cin >> t;
    cout << endl << "enter a certain payment to get the unpaid balance: " << endl;
    cin >> k;
    periodPay = PeriodicPayment(l, r, m, t);
    cout << endl << "the periodic payment is " << periodPay << endl
        << "the unpaid balance is " << unpaidBalance(m, t, k) << endl
        << "press any key to continue or 'n' to end ";
    cin >> ch;
    }
    while (ch != 'n');
    return 0;
}


double PeriodicPayment (double l, double r, double m, double t)
{
    i = r / m;
    periodPay = l * i / (1 - pow(1 + i, - m * t));

    return periodPay;
}

double unpaidBalance (double m, double t, double k)
{
    double remainBalance = periodPay * ((1 - pow(1 + i, - m * t - k )) / i);
    return remainBalance;
}
ibrahim sherif mohamed
ibrahim sherif mohamed
مبرمج جديد
مبرمج جديد
Posts : 9
Points : 1340
Reputation : 0
Join date : 11/08/2020

[تم الحل]a functions doesn't work properly Empty رد: [تم الحل]a functions doesn't work properly

الخميس أغسطس 20, 2020 11:53 pm
هو مش المفروض ان المتغير i و periodpay دول global يعني مرئين في الفنكشنز الي تحتيهم و اي تغير هيحصلهم هيتم استقباله في الفانكشن التانية ?
Ektb Code
Ektb Code

Posts : 54
Points : 1584
Reputation : 11
Join date : 05/05/2020
https://ektbcode.ahlamontada.com

[تم الحل]a functions doesn't work properly Empty رد: [تم الحل]a functions doesn't work properly

الجمعة أغسطس 21, 2020 5:00 pm
ال global variable تقدر تستخدمه في اي مكان فعلا لكن انت عرفته تحت الmain والصح انك تعرفه فوق الmain زي ما انا عملت وجرب تاني بالكود بتاعك وبلغني
ibrahim sherif mohamed
ibrahim sherif mohamed
مبرمج جديد
مبرمج جديد
Posts : 9
Points : 1340
Reputation : 0
Join date : 11/08/2020

[تم الحل]a functions doesn't work properly Empty رد: [تم الحل]a functions doesn't work properly

السبت أغسطس 22, 2020 11:02 am
تم الحل شكرا
الرجوع الى أعلى الصفحة
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى