Write a C program:The use of computers in education is referred to as computer-assisted instruction (CAI). Write a C program that will help an elementary school student learn multiplication. Use the rand function to produce two positive one-digit integers. The program should then prompt the user with a question, such as How much is 6 times 7' The student then inputs the answer. Next, the program checks the student's answer. If it's correct, display the message "Very good!" and ask another multiplication question. If the answer is wrong, display the message "No. Please try again." and let the student try the same question repeatedly until the student finally gets it right. A separate function should be used to generate each new question. This function should be called once when the application begins execution and each time the user answers the question correctly.

Question
Asked Mar 24, 2020
32 views

Write a C program:

The use of computers in education is referred to as computer-assisted instruction (CAI). Write a C program that will help an elementary school student learn multiplication. Use the rand function to produce two positive one-digit integers. The program should then prompt the user with a question, such as How much is 6 times 7' The student then inputs the answer. Next, the program checks the student's answer. If it's correct, display the message "Very good!" and ask another multiplication question. If the answer is wrong, display the message "No. Please try again." and let the student try the same question repeatedly until the student finally gets it right. A separate function should be used to generate each new question. This function should be called once when the application begins execution and each time the user answers the question correctly.

 

check_circle

Expert Answer

Step 1

Program approach –

  • Include the essential header files.
  • Declare the variables.
  • Define the function named ran_num .
  • In this function,user has to provide answers for the random generated questions on the console.
  • If the answer is correct , then the function returns the value 1 else it returns 0.
  • Define the main function.
  • The calling of function ran_num is done from this main function.
  • The value returned by the ran_num function is stored in the variable named check.
  • If the check is equal to 1, then display the message “Very good”.
  • Else display the message “No. Please try again”.

 

 

Step 2

Code ( in C ) -

 

#include<stdio.h>      // header file

#include<stdlib.h>

#include <time.h>

int inp1,inp2;

//

int ran_num()           // function

{

   int pdt,user_ans;

   srand(time(0));

   inp1=rand()%10;            // generating ranndom inp1

   inp2=rand()%10;              // generating ranndom inp2

    pdt=inp1*inp2;      // calculate the  product of inp1 and inp2

 // prompt user to provide the answer for the given question

   printf("\nHow much is %d times %d ? ",inp1,inp2);  

   scanf("%d",&user_ans);        // taking user answer

if(user_ans==pdt)         // checking for correctness

   return (1);              // if correct then return 1

   else

     return (0);         // for wrong return 0

}

int main()                     // main function

{

int check,pdt=-1,user_ans;

    while(1)

{

     check=ran_num();          // ran_num function calling

  

     if(check==1)                  // checking for correct answer

       printf("very good!");      // printing message

      else  &...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: 43. What are the difference between following instructions? LDR RO, [R1] LDRH RO, [R1] LDRB RO, [RI]

A: Answer: Addressing mode: LDR, LDRH, and LDRB are the memories which are addressed by a register and...

question_answer

Q: Who decides how and when data in an organization will be used or controlled? Who is responsible for ...

A: Data: Data of the organization consists of all the confidential information. Data can be any of the...

question_answer

Q: Getting the error "The left-hand side of an assignment must be a variable"  in these lines  System.o...

A: The given Statement is: System.out.println("totalWithholding: $" = stateTax + federalTax); System.ou...

question_answer

Q: A (n)    is a line style applied to individual cells, and entire tables , or individual areas within...

A: a) Border, is the correct option.

question_answer

Q: So I am getting an error when I submit my c++ code. The prompt for the hw was as follows: Create 2 f...

A: #include &lt;iostream&gt; #include &lt;cmath&gt; using namespace std;   int i, j; // to iterate the ...

question_answer

Q: In C++, what is the benefit of using typedefs in a program? Here is an exmaple line of code: typedef...

A: Benefits of using typedef:   In C++, typedef allows to define the new data type explicitly. i.e., i...

question_answer

Q: Here's my C++ programming coding assignment for 4-11: Instructions Write a program that implements t...

A: Note: The changes made in the code are in bold for your reference. Also, we have included “$” symbol...

question_answer

Q: For questions 6-9, create a truth table for each statement. 6. A ⋀ ~B 7. ~(~A ⋁ B) 8. (A ⋀ B) → C 9....

A: Operators used – ⋀ - it is “and” operator. If both A and B are true then the result will be true, el...

question_answer

Q: The first question is: 1-Explain how the three characteristics of big data (volume, velocity, and va...

A: Hey, since there are multiple questions posted, we will answer first question. If you want any speci...