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...
-
(a) Find the equivalent resistance between points a and b in Figure P28.6. (b) A potential difference of 34.0 V is applied between points a and b. Calculate the current in each resistor. 7.00 9.00 ...
-
A cyclist travels 10.0 km east in a time of 11 min 40 s. What is his average velocity in meters per second?
-
Divide the methanol reaction operation in Example 6.6 into five consecutive stages in series. Feed the \(\mathrm{CO}\) reactant entirely into the first operation at \(25^{\circ} \mathrm{C}\) and \(1...
-
Carreras Caf is a Spanish restaurant in a college town. The owner expects that the number of meals served in June will be 40 percent below those served in May, because so many students leave for the...
-
Evaluate the principles of crystallization in microgravity environments, considering how reduced gravitational forces impact nucleation, growth, and aggregation, and discussing the potential for...
-
Workers used to be able to smoke inside office buildings. Smoking bans were introduced in several areas in the 1990's. Supporters of these bans argue that in addition to elim- inating the externality...
-
A cylindrical container 80 cm long is separated into two compartments by a thin piston, originally clamped in position 30 cm from the left end. The left compartment is filled with one mole of He at a...
-
Questions about the company Cheesecake Factory Texas Road House. General Information: 1 What is the name and ticker symbol of the corporation? 2 Where are the corporate headquarters? 3 When was the...
-
How did you calculate Amortization accrued: $ 7 2 , 0 0 0 per period x 2 years and 2 months = $ 1 6 0 , 8 0 0?
-
The purpose of this part is to provide you with a better understanding of the origins of the Codification. For this part, you should stay in the Codification, clicking on the tab Other Sources ( on...
-
Isaac Berman is a former finance manager. When he was downsized, he applied to NYU s Stern School of Business and was accepted with a full scholarship. His wife, Salom , has a law degree. Since she...
-
1 . Mortgagor purchases a parcel of land from Seller for $ 1 0 0 , 0 0 0 . Mortgagor borrows $ 8 0 , 0 0 0 from Bank and pays that amount and an additional $ 2 0 , 0 0 0 of cash to Seller giving Bank...
-
How many positive integers less than 500 can be formed using the numbers 1,2,3,and 5 for digits, each digit being used only once.
-
1. Advertising for eyeglasses _________ (increases/decreases) the price of eyeglasses because advertising promotes _________. 2. An advertisement that succeeds in getting consumers to try the product...
-
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...
-
An extremely intriguing feature of quantum entanglement is a property that has been called the "monogamy of entanglement": a particle can only be maximally entangled with precisely one other...
-
We had mentioned that from the partition function \(Z\), all possible thermodynamical quantities can be determined. In this problem, we will use the harmonic oscillator's partition function of Eq....
-
Let's consider the harmonic oscillator immersed in a heat bath of temperature \(T\). For any Hermitian operator \(\hat{A}\), we can define its thermal average denoted as...
Study smarter with the SolutionInn App