Question Write the program that acts as a simple calculator (with 3 operators + - *) for whole numbers. Notice that divi
Posted: Fri Jul 01, 2022 6:16 am
Question Write the program that acts as a simple calculator (with 3 operators + - *) for whole numbers. Notice that division is not included. The input numbers and result are expressed by diamonds as well as numbers. You MUST express a diamond using two ‘/’ and two ‘\’ at 2 sentence lines as shown below. Change the raw for every 10 diamonds.
Example of displaying 15 diamonds:
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
/\ /\ /\ /\ /\
\/ \/ \/ \/ \/
The program should:
1. Prompt the user with the following message:
Enter two numbers and an operator in the form number1 operator number2 (e.g. 4 - 2): 2 * 12
2. Display the first input numbers and corresponding number of diamonds.
The first number is 2
/\ /\
\/ \/
3. Display the second input numbers and corresponding number of diamonds.
The second number is 12
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
/\ /\
\/ \/
4. Display result including input equation, result (number), and result (diamonds) as shown below.
2 * 12 is 24
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
/\ /\ /\ /\
\/ \/ \/ \/
5. If input operator is invalid, display the warning message with input operator. Below is an example when the input operator is ‘#’, which is invalid.
Invalid operator #.
Below is the example of entire program.
Enter two numbers and an operator in the form
number1 operator number2 (e.g. 4 - 2): 6 + 9
The first number is 6
/\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/
The second number is 9
/\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/
6 + 9 is 15
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
/\ /\ /\ /\ /\
\/ \/ \/ \/ \/
Shown in boldface are example user inputs.
Note
• Use at least 1 your own function to make main function simple.
• One function must be about displaying diamonds for the given number.
• You must follow the instruction of displaying diamonds. Other shape is not accepted.
• You may assume that the human user always enters whole number.
• Use meaningful variable name.
• Optimize your conditional statements for efficiency and easy reading.
• Remember to style your code properly including comments.
END
Subject: C Programming
Kindly input comments of each command. Thank you.
Example of displaying 15 diamonds:
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
/\ /\ /\ /\ /\
\/ \/ \/ \/ \/
The program should:
1. Prompt the user with the following message:
Enter two numbers and an operator in the form number1 operator number2 (e.g. 4 - 2): 2 * 12
2. Display the first input numbers and corresponding number of diamonds.
The first number is 2
/\ /\
\/ \/
3. Display the second input numbers and corresponding number of diamonds.
The second number is 12
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
/\ /\
\/ \/
4. Display result including input equation, result (number), and result (diamonds) as shown below.
2 * 12 is 24
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
/\ /\ /\ /\
\/ \/ \/ \/
5. If input operator is invalid, display the warning message with input operator. Below is an example when the input operator is ‘#’, which is invalid.
Invalid operator #.
Below is the example of entire program.
Enter two numbers and an operator in the form
number1 operator number2 (e.g. 4 - 2): 6 + 9
The first number is 6
/\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/
The second number is 9
/\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/
6 + 9 is 15
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
/\ /\ /\ /\ /\
\/ \/ \/ \/ \/
Shown in boldface are example user inputs.
Note
• Use at least 1 your own function to make main function simple.
• One function must be about displaying diamonds for the given number.
• You must follow the instruction of displaying diamonds. Other shape is not accepted.
• You may assume that the human user always enters whole number.
• Use meaningful variable name.
• Optimize your conditional statements for efficiency and easy reading.
• Remember to style your code properly including comments.
END
Subject: C Programming
Kindly input comments of each command. Thank you.