write a C program to practice simple mathematical operations (Addition, Subtraction, Multiplication, Division) with integer numbers....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
write a C program to practice simple mathematical operations (Addition, Subtraction, Multiplication, Division) with integer numbers. This project serves to reinforce the C fundamentals, control flow, functions, expressions, and random number generation. It is important to review the rand () and srand () functions and understand how to generate random numbers in an interval because they are widely used for this implementation. Overview: Mental calculation is understood as a series of mental procedures that a person performs without the help of calculator or paper and pencil, and that allows him or her to obtain the exact answer to simple arithmetic problems. Arithmetic operations play a fundamental role in mental calculation and contribute to the development of skills when they are practiced. In this project you will code the Math R@ce game to practice basic math operations. At the start of the race, the player will be positioned at the starting line and each correct answer will advance one step. The race has a total of 10 consecutive operations and, if the player gets them all right, the race is successful, otherwise a message is displayed indicating the missing steps to reach the finish line. Instructions: The game displays a welcome message and asks for the player's name, as follows: Welcome to Math Rece Player's name: After, a menu with these options is displayed asking you to enter the desired option. Player's name: After, a menu with these options is displayed asking you to enter the desired option. 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Quit Select an option: If the option is invalid (a number out of range or a different data type), then an Error message will be displayed, and the player will be prompted again to enter a valid option. . Once an option is selected, the program shows a message of the arithmetic operation and a Race counter of the form #/10, where #= [0-10]. It starts at 0 and is updated considering the correct answers. Also, a Racing line is displayed with the symbols '@' (the player's position),'__' (the race path) and "%" (the finish line). Each symbol will be on the same line separated by a tab. The position where '@' appears is in relation to the correct answers given so far. Finally, the message is displayed, which starts the game only when the "Return" key is pressed. Assume the player selects Addition, what was described above would be displayed as follows: Math Rece- Addition Race counter: 0/10 The game starts displaying operation #: an arithmetic operation (of the corresponding category) with 2 integers generated at random (see Section restrictions for more details). Below the operation are shown 3 choices labeled a, b, c (one of them with the right answer and others created at random); and the "Answer: "message to get the player's choice. The program must verify that the choice is valid ('a', 'b', 'c', 'A', 'B', 'C), if not, "Answer: "is displayed again. If choice is valid, a message ("Correct!" or "Incorrect"), the Race counter and the Racing line are displayed. Only if the answer is correct, the Race counter is updated and @is moved one position forward. Example: Operation 1: 8 + 45 a 34 b 53 c 43 Operation 1: 8 + 45 a 34 b 53 c 43 Answer: b Correct! Race counter: 1/10 After completing all 10 consecutive operations, a status race message, and the option to return to the menu are displayed. If the player reaches the finish line "Congratulations ! you reached the finish line." is shown, otherwise is displayed "You did not finish the race " "You were missing steps to reach the finish line.". Note and are replaced by actual values. Example of a successful race after entering the answer for the 10th operation: Race counter: 10/10 Congratulations Tony Stark! You reached the finish line. Press to go back to the menu: Required Functions: The program must contain at least the following functions: int menu (...) Displays the menu with all options and retrieves user input. int is_valid_option (...) Checks if the menu entry is the correct range and type (int). void race_status (...) Prints the Race counter and Racing line. A function with logic for each mathematical operation void addition () void subtraction (...) void multiplication (...) void division (...) Choose the appropriate parameters (...) for each of the following functions. You can create additional functions that help you better organize the game logic. Guidelines: Global variables are not allowed. The player's name may contain blank spaces and may not be more than 35 characters. Initialize random seed with srand (time (NULL)) ;. The seed is initialized only once, i.e., you must not call this function again during run. . Mathematical operations: An operation involves only 2 operands. . A choice must meet the following restrictions: Must be an integer [0-100]. They must be different from each other. The correct answer must always appear among the options. The correct answer cannot always appear in the same option. . . Operands are integers in the range [0-100]. The result of any operation is always an integer in the range [0-100]. Not valid example in divisions: 17/3 Not valid example in subtractions 3 5 The same two operands cannot appear consecutively in the race. Example: current operation is 5 + 78, next operation can't be 5 + 78 nor 78 + 5. . write a C program to practice simple mathematical operations (Addition, Subtraction, Multiplication, Division) with integer numbers. This project serves to reinforce the C fundamentals, control flow, functions, expressions, and random number generation. It is important to review the rand () and srand () functions and understand how to generate random numbers in an interval because they are widely used for this implementation. Overview: Mental calculation is understood as a series of mental procedures that a person performs without the help of calculator or paper and pencil, and that allows him or her to obtain the exact answer to simple arithmetic problems. Arithmetic operations play a fundamental role in mental calculation and contribute to the development of skills when they are practiced. In this project you will code the Math R@ce game to practice basic math operations. At the start of the race, the player will be positioned at the starting line and each correct answer will advance one step. The race has a total of 10 consecutive operations and, if the player gets them all right, the race is successful, otherwise a message is displayed indicating the missing steps to reach the finish line. Instructions: The game displays a welcome message and asks for the player's name, as follows: Welcome to Math Rece Player's name: After, a menu with these options is displayed asking you to enter the desired option. Player's name: After, a menu with these options is displayed asking you to enter the desired option. 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Quit Select an option: If the option is invalid (a number out of range or a different data type), then an Error message will be displayed, and the player will be prompted again to enter a valid option. . Once an option is selected, the program shows a message of the arithmetic operation and a Race counter of the form #/10, where #= [0-10]. It starts at 0 and is updated considering the correct answers. Also, a Racing line is displayed with the symbols '@' (the player's position),'__' (the race path) and "%" (the finish line). Each symbol will be on the same line separated by a tab. The position where '@' appears is in relation to the correct answers given so far. Finally, the message is displayed, which starts the game only when the "Return" key is pressed. Assume the player selects Addition, what was described above would be displayed as follows: Math Rece- Addition Race counter: 0/10 The game starts displaying operation #: an arithmetic operation (of the corresponding category) with 2 integers generated at random (see Section restrictions for more details). Below the operation are shown 3 choices labeled a, b, c (one of them with the right answer and others created at random); and the "Answer: "message to get the player's choice. The program must verify that the choice is valid ('a', 'b', 'c', 'A', 'B', 'C), if not, "Answer: "is displayed again. If choice is valid, a message ("Correct!" or "Incorrect"), the Race counter and the Racing line are displayed. Only if the answer is correct, the Race counter is updated and @is moved one position forward. Example: Operation 1: 8 + 45 a 34 b 53 c 43 Operation 1: 8 + 45 a 34 b 53 c 43 Answer: b Correct! Race counter: 1/10 After completing all 10 consecutive operations, a status race message, and the option to return to the menu are displayed. If the player reaches the finish line "Congratulations ! you reached the finish line." is shown, otherwise is displayed "You did not finish the race " "You were missing steps to reach the finish line.". Note and are replaced by actual values. Example of a successful race after entering the answer for the 10th operation: Race counter: 10/10 Congratulations Tony Stark! You reached the finish line. Press to go back to the menu: Required Functions: The program must contain at least the following functions: int menu (...) Displays the menu with all options and retrieves user input. int is_valid_option (...) Checks if the menu entry is the correct range and type (int). void race_status (...) Prints the Race counter and Racing line. A function with logic for each mathematical operation void addition () void subtraction (...) void multiplication (...) void division (...) Choose the appropriate parameters (...) for each of the following functions. You can create additional functions that help you better organize the game logic. Guidelines: Global variables are not allowed. The player's name may contain blank spaces and may not be more than 35 characters. Initialize random seed with srand (time (NULL)) ;. The seed is initialized only once, i.e., you must not call this function again during run. . Mathematical operations: An operation involves only 2 operands. . A choice must meet the following restrictions: Must be an integer [0-100]. They must be different from each other. The correct answer must always appear among the options. The correct answer cannot always appear in the same option. . . Operands are integers in the range [0-100]. The result of any operation is always an integer in the range [0-100]. Not valid example in divisions: 17/3 Not valid example in subtractions 3 5 The same two operands cannot appear consecutively in the race. Example: current operation is 5 + 78, next operation can't be 5 + 78 nor 78 + 5. .
Expert Answer:
Answer rating: 100% (QA)
Creating a complete C program that implements the Math Race game as described is quite a lengthy tas... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
In this exercise, you will create a monthly income statement, statement of owner s equity, and balance sheet in Excel for Pro Painting Inc. With the exception of the Giovanni Keith, Capital account (...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Explain the basic skills and traits a food and beverage manager must have in order to be successful. Discuss the function of the accounting department in relation to the food and beverage department....
-
The ordinary share capital of PP Ltd (a trading company) is owned 32% by QQ Ltd, 35% by RR Ltd and 23% by SS Ltd. The remaining 10% is owned by various individuals, none of whom own more than 1%. All...
-
Fidelity Corporation offers to hire Ron to replace Monica, who has given Fidelity a month's notice to quit. Fidelity gives Ron a week to decide whether to accept. Two days later, Monica signs an...
-
If a group of investors tends to buy and sell together, are these investors herding? Explain why or why not.
-
Yale Corporation issued to Zap Corporation \(\$ 60,000,8 \%\) (cash interest payable semiannually on June 30 and December 31) 10-year bonds dated and sold on January 1, 2020. Assume that the company...
-
Alena Co. was organized on July 1, 2017. Quarterly financial statements are prepared. The unadjusted and adjusted trial balances as of September 30 are shown below. Instructions (a) Journalize the...
-
You are required to write a paragraph about a business that you may wish to operate in the future. It must be a service business, that is, it will not buy and sell goods, rather it will provide a...
-
The names of the employees of Matson Office Systems and their regular salaries are shown in the following payroll register. Note that Wayne and Young are paid monthly on the last payday, while all...
-
Mandy Cosby, a citizen of Tennessee, was walking along a street in Northfield Tennessee when metal poles slid off the top of a truck and hit her, and caused her injuries. She was severely injured....
-
Calculate the amount of money to be included on the CD for the following scenario: Purchase price is $205,000. Loan amount is $190,000. The per diem interest on buyer's loan is $23.61. The lender is...
-
Requirements 1. How many jeans must Right Fit sell in order to break even? 2. How many jeans must the company sell in order to reach a. A target operating income of $300,000? b. A net income of...
-
A company has $400 million worth of debt outstanding with an average interest rate of 5% and 50 million common shares outstanding worth $12 each. The company's tax rate is 28%, beta is 1.3, the yield...
-
Store Revenues Costs 101 $4,100 $4,214 102 2227 2894 103 5,738 5,181 104 3982 3998 105 2,914 3,676 106 4,023 3,319 107 6,894 5,029 108 1,779 2,374 109 5,416 4,688 110 3,228 2,959 111 3,886 4,179 112...
-
You purchase an MBS 9, 30 year with a face value of $100,000 a) What is your monthly payment? b) What is the interest and principal earned over 5 years c) What will the MBS be priced at the following...
-
A new restaurant wants to investigate its menu items to see where they need to add or subtract some items from its lunch menu. It collected data over a random lunch service. In a random sample of...
-
What is an access control list?
-
Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. A private int data field named...
-
Write a recursive method to return the number of uppercase letters in a string. Write a test program that prompts the user to enter a string and displays the number of uppercase letters in the string.
-
Write two programs, such that one displays the mouse position when the mouse button is clicked (see Figure 15.26a) and the other displays the mouse position when the mouse button is pressed and...
-
Should a business accept or reject a project with an NPV of zero? Explain your reasoning.
-
Do you think there would ever be a situation when a company should proceed with a capital project even though the project promises a return lower than the cost of capital? Explain your reasoning.
-
How would you explain the difference between present value and net present value?
Study smarter with the SolutionInn App