Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C language only. THE PROBLEM: We have discussed the importance of knowing what type of data we are dealing with in programming. We see how
C language only.
THE PROBLEM: We have discussed the importance of knowing what type of data we are dealing with in programming. We see how 256-765-4601 to the human brain has two meanings, a telephone number or an arithmetic expression. We know that to be an arithmetic expression, the numbers would be read and stored as integers. If the item above is to be read as a telephone number, it would need to be stored as a string (a list of characters). In general, when the integer 22 is stored, the binary representation of 22 is stored in a memory location. When 8 the character is stored, something else is stored... the ASCII representation (mapping) for the character 8 is stored. The ASCII code for the character 8 is the integer 56, so when stored, the binary representation of 56 is stored for the character 8.
Below is a list of the ASCII codes for all of the numerical digits:
0 ->48,
1 ->49
2 ->50
3 ->51
4 ->52
5 ->53
6 ->54
7 ->55
8 ->56
9->57
In certain programming situations, such as getting information from web forms, via text boxes, the data coming in may need to be numerical (we want to perform arithmetic on it), but it is stored in the form of a list of characters (the numerical value stored is based upon the table above). Therefore, as the programmer, we must convert the character to an integer digit or the string containing digits as characters to its decimal equivalent.
Your job:
For this project, you will simulate this conversion. Your program will ask the user to enter a 4 digit numerical value. As the programmer, you will input the value as a string. You will devise an algorithm to convert the string of characters (string of digits) to a single integer, stored in a single integer value. At the end of this algorithm, you will print the addition (using the + operator) of the input string to itself, and the addition of the converted integer to itself.
For example, if the user were to input 9275, the outputs would be 18550 and 92759275.
Your program should generate appropriate error messages if the user enters: (1) less than 4 digits, (2) more than 4 digits, or (3) any non-numeric digits.
Constants should be used in place of literals where appropriate.
Inline comments should comment any statement or group of statements that might need detail about what the code is doing.
Meaningful variable and constant names should match the intent or the purpose of the data item use words, not abbreviations.
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