السلآم عليكم ورحمةة الله وبركآتهه :)
إمم عندي سؤآل يطلب كود آله حآسبهه بس إنه يجي منيو و إنت تختآر آي عمليه تبغى
وهذآ السؤآل :
اقتباسWrite and run a program that simulates a simple calculator . It reads two integer and number of a operation choice. if f the choice is 1 , the sum (+) printed if it is 2 the defference (-)is prented
. if it is 3 the product result (*) is printed if it is 4 the quotient is printed . use a switch statement
حليت السؤآل أنآ : بس مآيجي نفس المطلوب وهذآ هو الكود اللي حليتهه :
#include <iostream.h>
int main ()
{
int num1,num2,result;
char operation;
cout<<"please enter your first integer:";
cin>>num1;
cout<<"Please enter your second integer:";
cin>>num2;
cout<<"Please enter your operation:";
cin>> operation;
switch (operation)
{
case '+': cout<<num1+num2<<endl; break;
case '-': cout<<num1-num2<<endl; break;
case '*': cout<<num1*num2<<endl; break;
case '/': cout<<num1/num2<<endl; break;
default: cout<<"you enter the wrong choise"<<endl;
}
return 0;
}وهذي المخرجآت :
please enter your first integer:5 Please enter your second integer:8 Please enter your operation:* 40 Press any key to continue
لكن المطلوب في السؤآل تكون المخرجآت :
please enter your first integer:5 Please enter your second integer:8 *******Menu ******** to calculate + press 1 to calculate - press 2 to calculate * press 3 to calculate / press 4 result=40 Press any key to continue
السؤآل : كيف أجيب المطلوب بشكل صحيح !
يعني أدخل الـ if -eise دآخل الـswitch عشآن ينحل السؤآل
و إلآ يجي ب الـswitch لحآلهه ؟
مُمتَنّه لكم مقدمآ ()