السلام عليكم ورحمة الله وبركاته
هذاالسؤال
A program is required which is to simulate computations carried out on a certain type of simple pocket calculator , as follows . the user enters a first value . then the user enters an operator – which can be + ( addition) or – (subtraction) or * (multiplication) or / (division) – followed by an operand ( second value ). ( the entering of an operator and an operand can be repeated anu number of times .) the operation is carried out on the current value and the operand , the answer becoming the revised current value and . when the ' = ' key is pressed instead of one of four operators , the result of the calculation is to be output .
بس السؤال يبي يحسب الارقام اللي على الشكل
9 * 8 - 7 +23 /12
طبعا حسب الاولويه
واذا ضغطت يساوي يطلع الناتج
بس انا حاولت بس ماقدرت الا على رقمين بس
وهذي تجربتي
- #include "stdafx.h"
- #include <iostream>
- using namespace std
- int main()
- {
- float i,j, ans
- char op
- cout << "Enter first value ." << endl
- cout << "Enter op ." << endl
- cin>>i>>op>>j
- while ( op != '=' ) {
- switch (op)
- {
- case '+':
- ans=i+j
- break
- case '-':
- ans=i-j
- break
- case '*':
- ans=i*j
- break
- case '/':
- if ( j != 0 ){
- ans=i/j
- }//end if
- else{
- cout <<"can not divided over 0 "
- }//end else
- break
- }// end switch
- }// end while
- cout << ans << endl
- return 0
- }
البرنامج مافيه اخطا بس مايشتغل
وشكرا
:::
::
:
