473,653 Members | 2,968 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generate multiplication tables

24 New Member
Can somebody please help me with the following problem. I need to submit the problem on Monday.

A program is required which could be used to help a child practice their multiplication tables. The program should start by asking the user how many multiplication problems they would like to try, and read this value from the keyboard. Then, the program should present to the user that many multiplication problems and allow the user to enter an answer for each.
After each answer is input, the program should print a message indicating that the answer is correct, or if it is not correct, display the correct answer. When all the problems are done, the program should print the percentage of problems answered correctly.

Below is a sample run of such a program and you can model your output on it if you wish. The user input is shown in boldface.
How many problems would you like? 3
Question 1: what is 6 x 8? 48
Correct!

Question 2: what is 7 x 3? 28
No, 7 x 3 is 21

Question 3: what is 4 x 5? 20
Correct!

Your score is 66.6%
The numbers used in the problems must all be in the range 1..12 and must be randomly generated. The expression below will generate a random integer in the range 1..12:
srand(time(NULL ));
int j=1+(int) (12.0*rand()/(RAND_MAX+1.0)) ;

where j is a random number between 1 and 12.

I wrote the solution for the problem but the problem is that my solution doesn't show the score. And secondly, my solution generates the same question repeatedly.

Please, please help me.

Thanxxxxxx in advance.

My code:

Expand|Select|Wrap|Line Numbers
  1. #include<cstdlib.h>
  2. #include<iostream.h>
  3.  
  4. int main()
  5. {
  6.     int user=0,i, num1, num2, count=0; //variable declaration
  7.     double answer, score=0, totalPercentage; //variable declaration
  8.  
  9.     cout<<"How many problems would you like? ";
  10.     cin>>user;
  11.  
  12.     srand(time(NULL)); //calling srand function
  13.  
  14.     for(i=1;i<=user;i++)
  15.     {
  16.           num1=1+(int) (12.0*rand()/(RAND_MAX+1.0));//generates first random number
  17.  
  18.           num2=1+(int) (12.0*rand()/(RAND_MAX+1.0));//generates second random number
  19.  
  20.           cout<<"Question "<<numOfQuestion<<":"<<" what is "<<num1<<" X "<<num2<<"? ";
  21.  
  22.     cin>>answer;
  23.  
  24.     if (answer==(num1*num2))
  25.     {
  26.         cout<<"Correct!"<<endl;
  27.         count++;
  28.     }
  29.     else
  30.       {
  31.         cout<<"No, "<<num1<<" X "<<num2<<" is "<<num1*num2<<endl;
  32.     }
  33.     }
  34.     totalPercentage=(count*100)/user;
  35.     cout<<"Your score is "<<totalPercentage<<"%"<<endl;
  36.     return 0;
  37. }
Feb 13 '07 #1
5 5278
hirak1984
316 Contributor
for repetition of numbers for multiplication, you may first generate all the random numbers and keep it in array.

e.g : for 3 question array size will be3 or 6 depending upon you use one array or two.
while storing random numbers check if the new number generated already exists in the array or not.
then output questions using numbers from the array.

and for the percentage problem,is it giving error or not printing the correct percentage?
Feb 13 '07 #2
rajesh6695
96 New Member
Sample code is in c....try to implement in c++ once after understanding the c code...and also implement the average result.....

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. void main()
  5. {
  6.     int i,j,k,input,res,count;
  7.     clrscr();
  8.     printf("Enter How many u have to work out :");
  9.     scanf("%d",&i);
  10.     count=0;
  11.     do
  12.     {
  13.         j=(rand()%10);
  14.         k=(rand()%10);
  15.         res=j*k;
  16.         printf("What %d * %d is :",j,k);
  17.         scanf("%d",&input);
  18.         if(res==input)
  19.         {
  20.             printf("Right\n");
  21.         }
  22.         else
  23.         {
  24.             printf("Wrong the right answer is : %d\n",res);
  25.         }
  26.         count++;
  27.     }while(count<=i);
  28.     getch();
  29.     return 0;
  30. }
Feb 13 '07 #3
hirak1984
316 Contributor
this code can also repeate questions(logic ally).

one have to precheck if randomly generated numbers are repeated or not.I think repeatition was the main problem not the logic.

Sample code is in c....try to implement in c++ once after understanding the c code...and also implement the average result.....

#include<stdio. h>
#include<conio. h>
#include<stdlib .h>
void main()
{
int i,j,k,input,res ,count;
clrscr();
printf("Enter How many u have to work out :");
scanf("%d",&i);
count=0;
do
{
j=(rand()%10);
k=(rand()%10);
res=j*k;
printf("What %d * %d is :",j,k);
scanf("%d",&inp ut);
if(res==input)
{
printf("Right\n ");
}
else
{
printf("Wrong the right answer is : %d\n",res);
}
count++;
}while(count<=i );
getch();
return 0;
}
Feb 13 '07 #4
scan87
24 New Member
Thank you very much I have found out the solution of the problem.
Feb 13 '07 #5
rajesh6695
96 New Member
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #include <time.h>
  5. void main()
  6. {
  7.     int i,j[10],j_j[10],k[10],k_k[10],input,res,count,buf;
  8.     time_t t;
  9.  
  10.     clrscr();
  11.     printf("Enter How many u have to work out :");
  12.     buf=0;
  13.     scanf("%d",&i);
  14.  
  15.     srand((unsigned) time(&t));
  16.     for(count=0;count<10;count++)
  17.     {
  18.         j[count]=(rand()%10);
  19.         k[count]=(rand()%10);
  20.     }
  21.     for(count=0;count<10;count++)
  22.     {
  23.         do
  24.         {
  25.             j[count]=(rand()%10);
  26.             k[count]=(rand()%10);
  27.             if(j[count] == j_j[count])
  28.             {
  29.                 if(k[count] == k_k[count])
  30.                 {
  31.                     buf=1;
  32.                     j[count]=6;
  33.                     k[count]=7;
  34.                 }
  35.                 else
  36.                 {
  37.                     buf=0;
  38.                 }
  39.             }
  40.         }
  41.         while(buf);
  42.     }
  43.     count=0;
  44.     do
  45.     {
  46.         res=(j[count]*k[count]);
  47.         printf("What %d * %d is :",j[count],k[count]);
  48.         scanf("%d",&input);
  49.         if(res==input)
  50.         {
  51.             printf("Right\n");
  52.         }
  53.         else
  54.         {
  55.             printf("Wrong the right answer is : %d\n",res);
  56.         }
  57.         count++;
  58.     }while(count<=(i-1));
  59.  
  60.     for(count=0;count<10;count++)
  61.     {
  62.         k_k[count]=k[count];
  63.         j_j[count]=j[count];
  64.     }
  65.     printf("Press any key to continue...");
  66.     getch();
  67.     return 0;
  68.  
  69.  
  70. }
Above code will reduce the repetion but not completely....
Feb 14 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

28
2204
by: Jeff Lanfield | last post by:
Suppose I have users that can belong to organizations. Organizations are arranged in a tree. Each organization has only one parent organization but a user maybe a member of multiple organizations. The problem that I'm facing that both organizations and individual users may have relationships with other entities which are semantically the same. For instance, an individual user can purchase things and so can an organization. An individual...
54
8345
by: Andy | last post by:
Hi, I don't know if this is the correct group to post this, but when I multiply a huge floating point value by a really small (non-zero) floating point value, I get 0 (zero) for the result. This creates a big hole in a 32-bit timer routine I wrote. Questions. 1. Why does this happen? 2. Is there C macros/functions I can call to tell me when two non-zero numbers are multiplied and the
9
7996
by: Ralf Hildebrandt | last post by:
Hi all! First of all: I am a C-newbie. I have noticed a "strange" behavior with the standart integer multiplication. The code is: void main(void)
17
8010
by: Christopher Dyken | last post by:
Hi group, I'm trying to implement two routines to handle 32x32-bits and 64x64-bits signed integer multiplication on a 32 bits machine in C. It easy to find descriptions of non-signed multiplication, however, I haven't found any good descriptions for the signed counterpart. Does any of you have a good reference for this topic? Thanks in advance,
1
1642
by: ASP.Net programmer | last post by:
I have a few SQLDataAdapters which select a MAX() value from a few different tables. Here is a sample of the SQL statement: SELECT MAX(startdate) AS startdate FROM some_table1 WHERE (startdate <= GETDATE()) The problem I have is this: When I select a few of those SQLDataAdapters to generate a DataSet from them the list of DataAdapters shows:
11
4484
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any AutoNumber* fields in them. Correct me if I'm wrong, but I'm assuming this means that I cannot now alter these existing Access tables and change their primary key to an "AutoNumber" type. If I'm right about this, I need some suggestions as to the...
11
5220
by: Skybuck Flying | last post by:
Hello, type Tbig = array of byte; vAddTable : array of array of byte; // = value // = transport/carry vMulTable : array of array of byte;
1
1140
by: steffiella1989 | last post by:
1) Write a Java class, MultiplicationTable which will display the multiplication table the user selects from the command line: e.g java MultiplicationTable 5 will display 0 * 5 = 0 1 * 5 = 5 2 * 5 = 10 ... ...
1
9148
by: Sozos | last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help. #define index(i,j,power) (((i)<<(power))+(j)) void recMultiply(int i, int j, float a, int k, int l, float b, int x, int y, float c, int s); int i, j, k, s, matrixsize, blocksize, jj, kk, power, bsize; float sum, maxr, total=0.0, startmult, finishmult, multtime; float* A = NULL; float* B = NULL;
0
8283
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8590
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.