guys i need some help has anyone has the solution?

Write a program which will work as an arithmetic calculator. The program should prompt the user to enter the arithmetic operation that would like to perform, request two real numbers and print the result.
The program should be able to perform the following arithmetic operations, depending on the character that the user enters:
 ‘+’ Addition
 ‘-‘ Subtraction [Subtract the first from the second number, entered by the user]
 ‘*’ Multiplication
 ‘/’ Division [Divide the first by the second number, entered by the user].
As part of the solution a function should be developed which will take the following three parameters:
1. The character of the arithmetic operation to be performed
2. The first number to be used by the selected arithmetic operation
3. The second number to be used by the selected arithmetic operation
Hint: The program should validate the second number in this case. Division by zero is not allowed. In such a case the program should display a warning message to the user and ask him/her to retype a valid second number.
For this exercise use the CASE statement
Last edited on
well we are not here to do your homework, but this isn't a hard task
1
2
3
4
5
6
7
8
9
10
char operator;
cin >> operator;
switch (operator)
case '+' : cin >> value1 >> " " >> value2;
                cout << value1 + value2; break;
case '-' : cin >> value1 >> " " >> value2;
                cout << value1 + value2; break;
case '/' : cin >> value1 >> " " >> value2;
               if ( value2 == 0 ) cout << "div by 0 error"; break; //print some error
               else cout<< value1 / value2; break;


something along those lines is a good start
Topic archived. No new replies allowed.