- #1
Dembadon
Gold Member
- 659
- 89
This program has been assigned in my intro to programming course, which assumes no previous knowledge of programming. Up to this point we've only been required to write functions that accomplish specific tasks within a program. This is the first time we've been asked to design and write a full program.
These are the requirements for the program:
a) it will handle any single-digit addition, subtraction, multiplication, and division.
b) as a result of the math, there is a potential for up to three digit results, so the program must handle this
c) as a result of the subtraction process, it is possible to arrive at a negative answer; the program must handle this
d) the program must also manage incorrect input for all four input values and the operator. This means that if any non-digit value is entered as a numerator or denominator, if a zero is entered as a denominator, or if any character other than '+', '-', '*', or '/' is entered as an operator, the user must be informed and the program must be stopped immediately without any further processing
Here are a couple screenshots showing what the TUI looks like after the calculation has been made:
My issue:
I need to do some analysis to determine precisely when the answer will be negative and when the numerator will have two or three digits. I also need to know when the denominator will have two digits. The function used to print the green digits can only print one digit at a time, so I also need to find a way to separate my digits for the answer and print them individually at the correct location on the screen.
I started writing out all the possible fraction values a user could input and discovered that a brute force method here is unreasonable, as I would have to check a few thousand different combinations to get what I'm looking for. I need a more elegant mathematical approach that will lend to a readable and efficient function.
I've reasoned that the denominator can never be larger than 81, since only single digit values are allowed as input, so I do not need to test for a three-digit denominator. However, it is possible to have up to three digits in the numerator, so I will need to test for this and adjust my output to the screen accordingly.
Homework Statement
These are the requirements for the program:
a) it will handle any single-digit addition, subtraction, multiplication, and division.
b) as a result of the math, there is a potential for up to three digit results, so the program must handle this
c) as a result of the subtraction process, it is possible to arrive at a negative answer; the program must handle this
d) the program must also manage incorrect input for all four input values and the operator. This means that if any non-digit value is entered as a numerator or denominator, if a zero is entered as a denominator, or if any character other than '+', '-', '*', or '/' is entered as an operator, the user must be informed and the program must be stopped immediately without any further processing
Here are a couple screenshots showing what the TUI looks like after the calculation has been made:
My issue:
I need to do some analysis to determine precisely when the answer will be negative and when the numerator will have two or three digits. I also need to know when the denominator will have two digits. The function used to print the green digits can only print one digit at a time, so I also need to find a way to separate my digits for the answer and print them individually at the correct location on the screen.
Homework Equations
The Attempt at a Solution
I started writing out all the possible fraction values a user could input and discovered that a brute force method here is unreasonable, as I would have to check a few thousand different combinations to get what I'm looking for. I need a more elegant mathematical approach that will lend to a readable and efficient function.
I've reasoned that the denominator can never be larger than 81, since only single digit values are allowed as input, so I do not need to test for a three-digit denominator. However, it is possible to have up to three digits in the numerator, so I will need to test for this and adjust my output to the screen accordingly.
Last edited: