Question

In: Computer Science

Goals Practice loops and conditional statements Description Create a game for elementary school students to practice...

Goals Practice loops and conditional statements Description Create a game for elementary school students to practice multiplication. The application should display a greeting followed by a set of mathematical questions.  In each set the player is asked to enter a number from 1 to 9 to test multiplication skills or to press ‘E’ to exit the game.  The application checks if the number entered is indeed between 1 and 9 and if not displays a message inviting the player to try again.  Upon receiving a number in a proper range the application starts displaying multiplication questions with that number being multiplied by 0,1,2,…,10. For example, if the player entered number 3, the first question will be: “3 x 0 = ?”, the second: “3 x 1 = ?”, and so on with the last question being “3 x 10 = ?”  At any point the player can press ‘E’ to exit current set  For each question if an incorrect result is entered the application prompts the player to try again. The player can choose to try again or bypass. The application provides up to 4 replay attempts to answer the same question.  For each question, the maximum score is 5 points if answered correctly. If not, each replay attempt lowers the score by 1 point. For example, if the player answered a question wrong and then got it right on the first replay attempt, the score is 4 points. Once the set is finished, a score for the set is presented and the player is invited to try another set.

Solutions

Expert Solution

Answer: Here is a C++ code for your problem.
Hope this will help you :)

#include<bits/stdc++.h>
using namespace std;
int main(){
        do{
                cout<<"Welcome. Ready to Play?\nAt any moment you can press E to exit.\n";
                char ch;
                int ans=0; // final score
                cout<<"Enter the number: ";  
                cin>>ch;
                // exit the game when E is pressed
                if(ch == 'E' || ch == 'e')
                {
                        cout<<"Thank you for playing\n\n";
                        return 0;
                }
                int n = ch - '0';
                // check if the number is invalid
                if(n<1 || n>9)
                {
                        cout<<"Invalid number. Number should be between(1-9)\n";
                        continue;
                }
                // multiply number entered to (0-10)
                for(int i=0;i<=10;i++){
                        int score = 5;
                    // score for each replay will reduce by 1. Only 4 replays possible.
                        while(score>0){
                                cout<<n<<" x "<<i<<" = ?"<<endl;
                                string s;
                                cin>>s;
                                // exit the game when E is pressed
                                if(s == "E" || s == "e")
                                {
                                        cout<<"Score: "<<ans<<"\nThank you for playing\n\n";
                                        return 0;
                                }
                                int val = stoi(s);
                                if(i*n == val)
                                {
                                        ans+=score; // score for 1 iteration
                                        break;  
                                }
                                score--;
                                if(score>0){
                                        cout<<"TRY AGAIN! \n";
                                }
                        }               
                }
                cout<<"Score: "<<ans<<endl<<endl;
        }while(true);
        return 0;
}

Related Solutions

Goals Practice conditional statements Description Write a program to simulate a menu driven calculator that performs...
Goals Practice conditional statements Description Write a program to simulate a menu driven calculator that performs basic arithmetic operations (add, subtract, multiply and divide). The calculator accepts two numbers and an operator from user in a given format: For example: Input: 6.3 / 3 Output: 2.1 Create a Calculator class that has a method to choose the right mathematical operation based on the entered operator using switch case. It should then call a corresponding method to perform the operation. In...
Design a Python example that includes the following Basic concepts: Loops Conditional statements two of the...
Design a Python example that includes the following Basic concepts: Loops Conditional statements two of the advanced concepts: Encryption / Decryption, Lists / Dictionaries Please leave a Description of the program
Can you create a player vs computer Hangman game on MATLAB using nested loops, for loops,...
Can you create a player vs computer Hangman game on MATLAB using nested loops, for loops, if loops, while loops, arrays and conditional execution, as well as creating an image of the game board. The list below must be considered in the code. - Selecting a word from a dictionary (a text file) - Reading a single letter from the user - Building a character array showing the letters matched so far - Keeping count of the number of guessed...
2) Bon Air Elementary School has 300 students. The principal of the school thinks that the...
2) Bon Air Elementary School has 300 students. The principal of the school thinks that the average IQ of students at Bon Air is 110. To prove her point, she administers an IQ test to 20 randomly selected students. Among the sampled students, the average IQ is 107 with a standard deviation of 6, suggesting that the average IQ is lower than she thought. Based on these results, should the principal accept or reject her original hypothesis? Assume a significance...
Many elementary school students in a school district currently have ear infections. A random sample of...
Many elementary school students in a school district currently have ear infections. A random sample of children in two different schools found that 21 of 42 at one school and 15 of 35 at the other had this infection. Conduct a test to answer if there is sufficient evidence to conclude that a difference exists between the proportion of students who have ear infections at one school and the other. Find the test statistic.
Goals: Concepts related to conditional statements in Python. This is a Python program. You DON’T need...
Goals: Concepts related to conditional statements in Python. This is a Python program. You DON’T need loops for this. Below is the programming task. An employee is paid at a rate of $17.25 per hour for up to 40 regular hours worked in a week. If the employee works more than 40 hours, it is considered overtime. Any hours over 40 hours but less than or equal to 60 are paid at the overtime rate ($12.34 per hour). Any hours...
Language: C++ 3 Campus Travel Game This lab will practice using loops. We will construct a...
Language: C++ 3 Campus Travel Game This lab will practice using loops. We will construct a short computer game. Please look at the Test Cases for exact wording. For your game, the player’s goal is to reach campus exactly. The player starts 14 miles away and has up to 4 turns to reach campus. At each turn the play can ride either use a Bus, a Subway, or a Jetpack: Riding a Bus moves the player forward 2 miles each...
Suppose that a study of elementary school students reports that the mean age at which children...
Suppose that a study of elementary school students reports that the mean age at which children begin reading is 5.5 years with a standard deviation of 0.9 years. Step 1 of 2: If a sampling distribution is created using samples of the ages at which 45 children begin reading, what would be the mean of the sampling distribution of sample means? Round to two decimal places, if necessary.
Suppose that a study of elementary school students reports that the mean age at which children...
Suppose that a study of elementary school students reports that the mean age at which children begin reading is 5.3 years with a standard deviation of 1.2 years. Step 2 of 2 :   If a sampling distribution is created using samples of the ages at which 36 children begin reading, what would be the standard deviation of the sampling distribution of sample means? Round to two decimal places, if necessary.
Suppose that a study of elementary school students reports that the mean age at which children...
Suppose that a study of elementary school students reports that the mean age at which children begin reading is 5.4 years with a standard deviation of 1.1 years. Step 1 of 2: If a sampling distribution is created using samples of the ages at which 41 children begin reading, what would be the mean of the sampling distribution of sample means? Round to two decimal places, if necessary. Step 2 of 2: If a sampling distribution is created using samples...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT