I am a beginner and I need help writing a calculation program.
The program should be able to handle at least 8 operators, square, sin, cos, tan, powers, +, -, *, /.
The program should be able to handle all these things in one expression.
For example: v for square, s for sin, c for cos, t for tan and ^ for power. v(s3.4/5^8). T
he program needs to understand parenthesis. And square, sin, cos and tan should be used as a "prefix" (executed on the following operator).
And when '=' is put in the result is written out, the program resets and restarts.
And if you could put in some comentaries in the code, so I know waht you've dont. It would be very helpful for the future.
hello i'm mo3taz from egypt,
i,ve solved this problem but just for the operators +,-;
example input: 1+2+3-2+3-4+5.
out put: the result
don't forget the fullstop at the end
# include <iostream.h>
int main()
{
int sum = 0;
int x , y; // two successive numbers in the input between them
char test = 'r'; // an operator
char op; // stands for an operator
while (test == 'c' || test == 'r') // tests for continue(c) or restart (r)
{
if ( test == 'r')
{
sum = 0;
cout << "___________________________________________________________________";
cout << "\nplease enter some successive numbers between each two an operator\n";
cout << "the equation encludes just '+' or '-' ( example:1+2-3+4.) \n";
}
if (test == 'c')
{
cout << " please enter another sequence to add to the old sequence\n";
cout << "the old value was : " << sum << endl;
}
cin >> x;
cin >> op;
cin >> y;
if (op == '+')
sum = (sum + x + y);
elseif ( op == '-')
sum = (sum + x - y);
while (op != '.')
{
cin >> op;
if (op == '.') break ; // notice that the operator may be '.'
cin >> y ; // after entering the while loop
if (op == '+')
sum = (sum + y);
elseif (op == '-')
sum = (sum - y);
}
cout <<"the result of this sequenc is: \n:" << sum << endl;
cout << "please enter c to continue calculating to the old result\n";
cout << "please enter r to restart and calculate a new value\n";
cout << " please enter e to exit \n ";
cin>> test;
if (test == 'e')
break;
}
}
if there is any problem with this tell me , and i'll try to insert other operators
my e_mail is : [email protected]