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: - #include<cstdlib.h>
-
#include<iostream.h>
-
-
int main()
-
{
-
int user=0,i, num1, num2, count=0; //variable declaration
-
double answer, score=0, totalPercentage; //variable declaration
-
-
cout<<"How many problems would you like? ";
-
cin>>user;
-
-
srand(time(NULL)); //calling srand function
-
-
for(i=1;i<=user;i++)
-
{
-
num1=1+(int) (12.0*rand()/(RAND_MAX+1.0));//generates first random number
-
-
num2=1+(int) (12.0*rand()/(RAND_MAX+1.0));//generates second random number
-
-
cout<<"Question "<<numOfQuestion<<":"<<" what is "<<num1<<" X "<<num2<<"? ";
-
-
cin>>answer;
-
-
if (answer==(num1*num2))
-
{
-
cout<<"Correct!"<<endl;
-
count++;
-
}
-
else
-
{
-
cout<<"No, "<<num1<<" X "<<num2<<" is "<<num1*num2<<endl;
-
}
-
}
-
totalPercentage=(count*100)/user;
-
cout<<"Your score is "<<totalPercentage<<"%"<<endl;
-
return 0;
-
}
5 5278
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?
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",&input);
-
if(res==input)
-
{
-
printf("Right\n");
-
}
-
else
-
{
-
printf("Wrong the right answer is : %d\n",res);
-
}
-
count++;
-
}while(count<=i);
-
getch();
-
return 0;
-
}
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;
}
Thank you very much I have found out the solution of the problem.
- #include<stdio.h>
-
#include<conio.h>
-
#include<stdlib.h>
-
#include <time.h>
-
void main()
-
{
-
int i,j[10],j_j[10],k[10],k_k[10],input,res,count,buf;
-
time_t t;
-
-
clrscr();
-
printf("Enter How many u have to work out :");
-
buf=0;
-
scanf("%d",&i);
-
-
srand((unsigned) time(&t));
-
for(count=0;count<10;count++)
-
{
-
j[count]=(rand()%10);
-
k[count]=(rand()%10);
-
}
-
for(count=0;count<10;count++)
-
{
-
do
-
{
-
j[count]=(rand()%10);
-
k[count]=(rand()%10);
-
if(j[count] == j_j[count])
-
{
-
if(k[count] == k_k[count])
-
{
-
buf=1;
-
j[count]=6;
-
k[count]=7;
-
}
-
else
-
{
-
buf=0;
-
}
-
}
-
}
-
while(buf);
-
}
-
count=0;
-
do
-
{
-
res=(j[count]*k[count]);
-
printf("What %d * %d is :",j[count],k[count]);
-
scanf("%d",&input);
-
if(res==input)
-
{
-
printf("Right\n");
-
}
-
else
-
{
-
printf("Wrong the right answer is : %d\n",res);
-
}
-
count++;
-
}while(count<=(i-1));
-
-
for(count=0;count<10;count++)
-
{
-
k_k[count]=k[count];
-
j_j[count]=j[count];
-
}
-
printf("Press any key to continue...");
-
getch();
-
return 0;
-
-
-
}
Above code will reduce the repetion but not completely....
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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)
|
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,
|
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:
| |
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...
|
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;
|
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
...
...
|
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;
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |