Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this assignment you will be creating a new program to perform very simple calculations for a user. The general format will be very similar
For this assignment you will be creating a new program to perform very simple calculations for a user. The general format will be very similar to that of the Fortune Teller program, so feel free to reference that program for ideas. Be sure to test your program on the course server.
The calculator program should work as follows:
First the program should print a brief message explaining to the user what the program does.
Then the program allows the user to enter two values whose types are double. Each of these two values needs to be stored in its own variable.
Next the user enters a third value that corresponds to the operation that the user wants to have the program perform. For example, the user enters a for addition; a for subtraction; etc.
As the developer of the program, you get to choose which numbers correspond to which operation is to be performed. The mapping between numbers and the corresponding operations should be specified in the brief message that explains what your program does.
Then the program should perform the correct calculation based on the three values the user entered.
The program should be able to perform at least addition, subtraction, multiplication, and division.
Try performing division by You should get some sort of error. To fix this problem, include a check in the division portion of the code to test whether the user entered a as the denominator. If the user did enter a have the program print a warning message instead of performing the division operation.
If you can't complete the entire assignment, be sure to describe what you've completed in the comments at the beginning of the program. On the other hand, if you did extra work on the assignment and sometimes you will want to also describe the extra work in the comment at the beginning of the program.
Include a block of comments at the beginning of the program or add to the existing block that lists your name, section number, date, and the assignment number. Also include comments on any parts of the assignment you didn't finish or on any extra work you did. Include this comment block at the beginning of every assignment and lab.
For now we are going to assume that the user enters the right type of data eg a number for the values Later we will start to look at detecting and correcting user input errors. This is called input validation and is a big topic. You could try entering a letter instead of a number if you want typing controlC will stop the program.
To produce the program output do the following:
Type script outputtxt
Run the pwd command.
Run the program.
a Rerun the program several times with different inputs, testing different operations addition subtraction, etc
When you feel you have tested the program sufficiently type exit to halt the script command.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started