C++ program that will help elementary school students learn multiplication. Use rand function to produce two positive one digit integers

A program that will  help elementary school students learn multiplication. Use rand function to produce two positive one digit integers.

#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

#include<time.h>





void main()

{

                clrscr();



                int x[2],ans;

                time_t t;

                char c;

                do

                {

                                srand(time(&t));

                                x[0]=rand()%10;



                                srand(x[0]);

                                x[1]=rand()%10;



                                cout<<"\n\nWhat is "<<x[0]<<"times "<<x[1]<<" ?\nANS: ";

                                do

                                {

                                                cin>>ans;

                                                if(ans!=(x[0]*x[1]))

                                                                cout<<"\nWRONG! TRY AGAIN\n";

                                }while(ans!=(x[0]*x[1]));



                                if(ans==(x[0]*x[1]));

                                {

                                                cout<<"correct!\n\n\nDO YOU WANT TO CONTINUE?";

                                                cin>>c;

                                }

                                if(c=='N'||c=='n')

                                {

                                break;}



                }while(1);

 }



                                                                               

OUTPUT:



What is 5times 1 ?                                                             

ANS: 5                                                                         

correct!                                                                       

                                                                                

                                                                               

DO YOU WANT TO CONTINUE?y                                                      



                                                                                

What is 6times 7 ?                                                             

ANS: 48                                                                        

                                                                                

WRONG! TRY AGAIN                                                               

42                                                                             

correct!                                                                        

                                                                               

                                                                               

DO YOU WANT TO CONTINUE?n

No comments:

Post a Comment