Question

In: Computer Science

Write a program named problem.c to generate addition and subtraction math problems for a 4th grader....

Write a program named problem.c to generate addition and subtraction math problems for a 4th grader.

1. Your program will first ask user how many problems they want to do.

2. Repeat the following until you give user the number of problems that the user asks for.

  a. Display the question number

b. Generate a addition or subtraction problem using two random generated two digits (0-99).

- The odd number of problems (1,3,5,…) will be addition problems.

- The even number of problems (2,4,6,…) will be subtraction problems. For subtraction problem, swap two numbers if the first number is smaller than the second number.

c. Display the problem, then ask user to answer. If the user answers correctly the first time, the user gets 10 points for the problem. If the user does not answer correctly, you print the problem again, and ask the user to try again. If the user answers correctly second time, the user gets 5 points for this problem. You then display the total points that user gets.

4. Calculate and display the percentage. a. If the percentage is above or equal 93%, display “Excellent”. b. If the percentage is above or equal 87%, display “Very good”. c. Otherwise, print “Keep working hard.”

Output shown look like:

How many problems would you like to do today?4

Ok! You will be given 4 math problems.

Good luck with them! Press enter to start.

Question 1

92 + 11 = 103

Correct! 10 points. Total points: 10

Question 2

95 - 10 = 85

Correct! 10 points. Total points: 20

Question 3

31 + 56 = 87

Correct! 10 points. Total points: 30

Question 4

32 - 29 = 2

Wrong. Please try again.

32 - 29 = 3

Correct. 5 points. Total points: 35

You got 87.50%! Very Good!

Thank you for using my math problem generator!

Solutions

Expert Solution

#include<stdio.h>
#include<stdlib.h>
int main()
{
    //variable declaration
    int a,b,n,ans,point=0,count=0,i;
    double percentage;
    //ask for number of problems
    printf("\n How many problems would you like to do today?");
    scanf("%d",&n);
    //loop will continue from 1 to n
    for(count=1;count<=n;count++)
    {
       a=rand()%100; //generate first random number between 0 to 99 inclusive
       b=rand()%100; //generate second random number between 0 to 99 inclusive
       if(count%2==0) //check for even number
       { i=1; //set the counter for number of attempts
          printf("\n Question %d",count); //display the question number
          if(a<b) //swap if a<b
          {
             a=a+b;
             b=a-b;
             a=a-b;
           }
          while(i<3) //loop will continue 2 times at most
          {
               printf("\n %d - %d = ",a,b); //display the question
               fflush(stdin);
               scanf("%d",&ans);//read answer
             if(ans==(a-b) && i==1) //check the validity of answer in first attempt
               {
                   point = point+10; //update the point
                   printf("\n Correct! 10 points, Total points %d",point);
                   break;//terminate loop
                   }
                   else  
                   if(ans==(a-b) && i==2)//check the validity of answer in second attempt
               {
                   point = point+5;//update the point
                   printf("\n Correct! 5 points, Total points %d",point);
                   break;//terminate loop
                   }
                   else //display message for wrong answer
                   printf("\n Wrong. Please Try again");
                   i++; //increment the counter for while loop
               }            
               }
   else
   {
       i=1;
          printf("\n Question %d",count);  
          while(i<3)//loop will continue 2 times at most
          {
               printf("\n %d + %d = ",a,b);//display the question
               fflush(stdin);
               scanf("%d",&ans);//read answer
             if(ans==(a+b) && i==1) //check the validity of answer in first attempt
               {
                   point = point+10;//update the point
                   printf("\n Correct! 10 points, Total points %d",point);
                   break;//terminate loop
                   }
                   else
                   if(ans==(a+b) && i==2)//check the validity of answer in second attempt
               {
                   point = point+5;//update the point
                   printf("\n Correct! 5 points, Total points %d",point);
                   break;//terminate loop
                   }
                   else//display message for wrong answer
                   printf("\n Wrong. Please Try again");
                   i++;//increment the counter for while loop
               }            
               }
   }
   //display the final point
   printf("\n Total Points : %d",point);
   //computing the percentage
   percentage = (double)(point)/(n*10);
   percentage = percentage * 100;
   //block for percentage above or equal to 93
   if(percentage>=93)
   printf("\n You got %5.2lf! Excellent!",percentage);
   else
   if(percentage>=87) //block for percentage above or equal to 87
   printf("\n You got %5.2lf! Very Good!",percentage);
   else
   printf("\n You got %5.2lf! Keep working very hard",percentage);
   //display the thank you message
   printf("\n Thank you for using my math problem generator!");
}

OUTPUT


Related Solutions

Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The...
Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The program will add, subtract, multiply, or divide 2 numbers and provide the average of multiple numbers inputted from the user. You need to define a function named performCalculation which takes 1 parameter. The parameter will be the operation being performed (+,-,*,/). This function will perform the given prompt from the user for 2 numbers then perform the expected operation depending on the parameter that’s...
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers....
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers. Start your code by copying/pasting this information into an editor like notepad, notepad++, or IDLE: public class Main { public static void main(String[] args) { // Write your code here } } Sample input: Input first number: 125 Input second number: 24 Sample Output: 125 + 24 = 149 125 - 24 = 101 125 x 24 = 3000 125 / 24 = 5...
Write a C++ program to perform two-4 bit binary number operations including addition and subtraction. The...
Write a C++ program to perform two-4 bit binary number operations including addition and subtraction. The user will type in two-4 bit binary numbers with the selection of one of the operations. Then, the program will calculate the result of the calculation. Display two-4 bit binary numbers and the result from the calculation.
Need a program in java that creates a random addition math quiz The program should ask...
Need a program in java that creates a random addition math quiz The program should ask the user to enter the following The smallest and largest positive numbers to be used when generating the questions - The total number of questions to be generated per quiz - The total number of the quiz's to create from then the program should generate a random math (Just addition) quiz from what the user entered
Write a Behavioral model VHDL code that implements an ALU that can perform addition, subtraction, multiplication,...
Write a Behavioral model VHDL code that implements an ALU that can perform addition, subtraction, multiplication, shift right, shift left, logical NAND, and logical NOR. Write a VHDL test bench to test the ALU with at least one test vector per operation.
Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed...
Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed to use other libraries. Only this libraries are allowed to use: use library ieee; use ieee.std_logic_1164.all; Please do it correctly and include the comments for me to fully understand. Thank you.
Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed...
Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed to use other libraries only this is allowed to use library ieee; use ieee.std_logic_1164.all; Please write the comments for me to fully understand. Thank you.
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition....
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition. The program generates random math problems for students to answer. User statistics need to be kept in RAM as the user is playing the game and recorded in a text file so that they may be loaded back into the program when the student returns to play the game again. In addition, the youngster should be allowed to see how (s)he is doing at...
Python Programming 4th edition: Write a program that asks the user for the number of hours...
Python Programming 4th edition: Write a program that asks the user for the number of hours (float) and the pay rate (float) for employee pay role sheet. The program should display the gross pay with overtime if any and without overtime. Hints: Given base_hr as 40 and ovt_multiplier as1.5, calculate the gross pay with and Without overtime. The output should look like as follows: Enter the number of hours worked: Enter the hourly pay rate: The gross pay is $XXX.XX
Write a program named MyHometown_Icon.java. The program will be an application (i.e have a main method)....
Write a program named MyHometown_Icon.java. The program will be an application (i.e have a main method). It will be in the default package. It will import edu.wiu.StdDraw. Its main method will make calls to methods in StdDraw to draw something iconic about your hometown. Multiple colors should be used.Multiple primitive types will be used and the drawing will consists of more than 20 primitive shapes.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT