+ 1
Hi does anyone knows how to give me a tip on coding a calculator
I'm a newby and I need help on this if can give me an advice I'll be very thankful
2 odpowiedzi
+ 6
Sure Here are a few tips to help you get started.
-Start by identifying the basic operations you want your calculator to perform, such as addition, subtraction, multiplication, and division.
-Next, think about how you will take input from the user. One approach is to have the user enter the numbers and the operation they want to perform (e.g. "2 + 3") as a single string, and then parse that string to extract the numbers and operation.
-Create variables to store the numbers and the operation the user has entered.
-Write a function that takes the two numbers and the operation as arguments and returns the result of the calculation.
-Use a loop to continuously prompt the user for input and output the result of the calculation until the user decides to exit the program.
-Consider adding error handling to your code, so that the calculator can handle invalid input or operations gracefully
+ 1
Prompt the user to enter
1- number
2- Operator
3- number
Then evaluate and validate the operator sign using if else statement to print the result or an error.
Hint: user input return string type.