الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

خطاء في كتابة البرنامج

بدأه yasorno في 20 ديسمبر 2011 · 3 رد · 529 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

امم كتبت برنامج ولم اعرف اين الخلل في البرنامج هل من مساعده في اصلاحه ؟؟

#include<iostrea>
#include <cstdlib>
#include<ctime>
using namespace std;
int getRanNum(int range);
int main()
{

int A,B,C;
int choice, answer;

A=getRanNum(50);
B=getRanNum(50);
cout <<A<<" "<<B<<endl;

do
{
cout<<endl;
cout<<"choose 1 to solve multiplication problems"<<endl;
cout<<"choose 2 to solve addition problems"<<endl;
cout<<"choose 3 to solve subtraction problems"<<endl;
cout<<"choose 4 to solve division problems"<<endl;
cout<<"choose 5 to exit this program"<<endl;
cin>>choice;

switch (choice)
{
case 1:
C=A*B;
cout<<"plase enter the right answer"<<endl;
cin>>answer;
if (A*B==C)
{

cout<<"very good."
<<"your answer is correct"<<endl;
}
else
{
cout<<"no, Please try again."
<<"the answer is wrong"<<endl;
}
break;

case 2:
C=A+B;
cout<<"plase enter the right answer"<<endl;
cin>>answer;
if (A+B==C)
{
cout<<"very good."
<<"your answer is correct"<<endl;
}
else
{
cout<<"no, Please try again."
<<"the answer is wrong"<<endl;
}
break;
case 3:
C=A-B;
cout<<"plase enter the right answer"<<endl;
cin>>answer;
if (A-B==C)
{
cout<<"very good."
<<"your answer is correct"<<endl;
}
else
{
cout<<"no, Please try again."
<<"the answer is wrong"<<endl;
}
break;

case 4:
C=A/B;
cout<<"plase enter the right answer"<<endl;
cin>>answer;
if (A/B==C)
{
cout<<"very good."
<<"your answer is correct"<<endl;
}
else
{
cout<<"no, Please try again."
<<"the answer is wrong"<<endl;
}
break;

case 5:
cout<<"end the program"<<endl;
break;

defult:
cout<<"not availble choice"<< "please choose again"<<endl;
}while (choice!=5);

system("pause");
return 0;
}


int getRanNum(int range)
{
srand(time(0));
return (rand()%range)+1;
}

شاكراً حسن تعاونكم مقدماً ..

#2

الكود يعمل بنجاح بعد القليل من التعديلات

لقد حلت جميع اﻻخطاء البرمجية التى يصدرها المترجم كود بلوك

#include<iostream> // :isotrea
#include <cstdlib>
#include<ctime>

using namespace std;

int getRanNum(int range);

int main()
{

    int A,B,C;
    int choice, answer;

    A = getRanNum(50);
    B = getRanNum(50);
    cout <<A<<" "<<B<<endl;

    do
    {
        cout<<endl;
        cout<<"choose 1 to solve multiplication problems"<<endl;
        cout<<"choose 2 to solve addition problems"<<endl;
        cout<<"choose 3 to solve subtraction problems"<<endl;
        cout<<"choose 4 to solve division problems"<<endl;
        cout<<"choose 5 to exit this program"<<endl;
        cin>>choice;

        switch (choice)
        {
        case 1:
            C = A * B;
            cout<<"plase enter the right answer"<<endl;
            cin>>answer;
            if ((A*B) == C)
            {

                cout<<"very good."
                    <<"your answer is correct"<<endl;
            }
            else
            {
                cout<<"no, Please try again."
                    <<"the answer is wrong"<<endl;
            }
            break;

        case 2:
            C=A+B;
            cout<<"plase enter the right answer"<<endl;
            cin>>answer;
            if (A+B==C)
            {
                cout<<"very good."
                    <<"your answer is correct"<<endl;
            }
            else
            {
                cout<<"no, Please try again."
                    <<"the answer is wrong"<<endl;
            }
            break;
        case 3:
            C = A-B;
            cout<<"plase enter the right answer"<<endl;
            cin>>answer; // a nswer //
            if ( ( A-B ) == C )
            {
                cout<<"very good."
                    <<"your answer is correct"<<endl;
            }
            else
            {
                cout<<"no, Please try again."
                    <<"the answer is wrong"<<endl;
            }
            break;

        case 4:
            C = A / B;
            cout << "plase enter the right answer" << endl;
            cin >> answer;
            if (( A / B ) == C)
            {
                cout<<"very good."
                    <<"your answer is correct"<<endl;
            }
            else
            {
                cout<<"no, Please try again."
                    <<"the answer is wrong"<<endl;
            }
            break;

        case 5:
            cout<<"end the program"<<endl;
            break;

defult:
            cout<<"not availble choice"<< "please choose again"<<endl;
        }


    }
    while (choice != 5);

    system("pause"); // كانت فى لدوارة  do
    return 0; // كانت فى لدوارة  do
}

///////////////////// begina of get ran num
int getRanNum(int range)
{
    srand(time(0));
    return (rand()%range)+1;
}
////////////////////// end of get ...

تم تعديل هذه المشاركة بواسطة محمد ابوزايد في 21 ديسمبر 2011 في 09:47

1

post-15367-027053900%201340345097.gifpost-15367-087183200%201340344597.gif
post-247365-0-10080400-1379403554_thumb.

#3

جزاك الله خيراً اخي محمد على مساعدتي في الحل

وان شاء الله هذا العمل في ميزان حسناتك .

#4
yasorno كتب:

جزاك الله خيراً اخي محمد على مساعدتي في الحل

وان شاء الله هذا العمل في ميزان حسناتك .

آآآآآآآآآآآآآآآآآمين

مواضيع مشابهة