alexanderthegreat
asked on
mixing tables
I want to make a program that outputs the tables array's, not in this order but in a mixed order.
tables0[10]= "1 * 2 = ";
tables1[10]= "2 * 2 = ";
tables2[10]= "3 * 2 = ";
tables3[10]= "4 * 2 = ";
tables4[10]= "5 * 2 = ";
And i have no idea how to do that.
Please show me how that is done.
tables0[10]= "1 * 2 = ";
tables1[10]= "2 * 2 = ";
tables2[10]= "3 * 2 = ";
tables3[10]= "4 * 2 = ";
tables4[10]= "5 * 2 = ";
And i have no idea how to do that.
Please show me how that is done.
ASKER
Am i realy that bad in telling what i want to know?.
When a teacher wants to learn his students the tables
she learns them in order like: 1 * 2 = 2, 2 * 2 = 4,
3 * 2 = 6 etc.
Now when the students have learned the table of 2 in this case, they get a test, the test will not come out like this: 1 * 2 = ?, 2 * 2 = ?, 3 * 2 = 6.
No, it will come out in different ways like 3 * 2 = ?,
1 * 2 = ?, 2 * 2 = ?.
Thats what i wat in my program i want my program to test if the students know the table of 2, by letting my program output the tables in different ways.
Can you use my tables
tables0[10]= "1 * 2 = ";
tables1[10]= "2 * 2 = ";
tables2[10]= "3 * 2 = ";
tables3[10]= "4 * 2 = ";
tables4[10]= "5 * 2 = ";
Can you show me a working program hope its not to much to ask.
When a teacher wants to learn his students the tables
she learns them in order like: 1 * 2 = 2, 2 * 2 = 4,
3 * 2 = 6 etc.
Now when the students have learned the table of 2 in this case, they get a test, the test will not come out like this: 1 * 2 = ?, 2 * 2 = ?, 3 * 2 = 6.
No, it will come out in different ways like 3 * 2 = ?,
1 * 2 = ?, 2 * 2 = ?.
Thats what i wat in my program i want my program to test if the students know the table of 2, by letting my program output the tables in different ways.
Can you use my tables
tables0[10]= "1 * 2 = ";
tables1[10]= "2 * 2 = ";
tables2[10]= "3 * 2 = ";
tables3[10]= "4 * 2 = ";
tables4[10]= "5 * 2 = ";
Can you show me a working program hope its not to much to ask.
>>When a teacher wants to learn his students the tables
did you mean "When teacher wans to teach..."
try something like this:
int num;
srand((unsigned) time(NULL)); //seed random generator
num = rand();
num = num%5; //5 I assume number of tables
switch(num){
case 1://output tables1;
case 2://output tables2;
//and so on
}
did you mean "When teacher wans to teach..."
try something like this:
int num;
srand((unsigned) time(NULL)); //seed random generator
num = rand();
num = num%5; //5 I assume number of tables
switch(num){
case 1://output tables1;
case 2://output tables2;
//and so on
}
ASKER
Can you please show me a full working program that shows
these: tables0[10]= "1 * 2 = ";
tables1[10]= "2 * 2 = ";
tables2[10]= "3 * 2 = ";
tables3[10]= "4 * 2 = ";
tables4[10]= "5 * 2 = ";
but then in your formule.
thx already.
these: tables0[10]= "1 * 2 = ";
tables1[10]= "2 * 2 = ";
tables2[10]= "3 * 2 = ";
tables3[10]= "4 * 2 = ";
tables4[10]= "5 * 2 = ";
but then in your formule.
thx already.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Its not homework, just want to see some code's so that i can learn from them.
Can you tell me what the function's rand(), srand() does, i dont have an honost buyed compiler, they are to expensive so i dont have the documentation of the runtime library, maybe you know where i can download it for the compiler (visual c++ 6.0 its part of my microsoft visual studio).
Can you also explain what this does: num % 5.
I hope i'm not to much trouble.
Thanks already.
Can you tell me what the function's rand(), srand() does, i dont have an honost buyed compiler, they are to expensive so i dont have the documentation of the runtime library, maybe you know where i can download it for the compiler (visual c++ 6.0 its part of my microsoft visual studio).
Can you also explain what this does: num % 5.
I hope i'm not to much trouble.
Thanks already.
ASKER
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
void main(void)
{
int nummer0, nummer1, nummer2, nummer3,
nummer4, teller=0;
int num, i;
char tables0[10]= "1 * 2 = ";
char tables1[10]= "2 * 2 = ";
char tables2[10]= "3 * 2 = ";
char tables3[10]= "4 * 2 = ";
char tables4[10]= "5 * 2 = ";
srand((unsigned) time(NULL)); //seed random generator
for(i=0; i<5; i++){
num = rand();
num = num%5; //5 I assume number of tables
switch(num){
case 0:cout << tables0;
cin >> nummer0;
if(nummer0==2)
cout << "Goed" << endl;
else
{
cout << "Fout" << endl;
teller++;
}
break;
case 1:cout << tables1;
cin >> nummer1;
if(nummer1==4)
cout << "Goed" << endl;
else
{
cout << "Fout" << endl;
teller++;
}
break;
case 2:cout << tables2;
cin >> nummer2;
if(nummer2==6)
cout << "Goed" << endl;
else
{
cout << "Fout" << endl;
teller++;
}
break;
case 3:cout << tables3;
cin >> nummer3;
if(nummer3==8)
cout << "Goed" << endl;
else
{
cout << "Fout" << endl;
teller++;
}
break;
case 4:cout << tables4;
cin >> nummer4;
if(nummer4==10)
cout << "Goed" << endl;
else
{
cout << "Fout" << endl;
teller++;
}
break;
}
}
cout << "Aantal fouten antwoorden: " << teller << endl;
cout << "Aantal goede antwoorden: " << 5 - teller << endl;
}
Looks nice so far he!.
I only think it repeats to often the same tables, can you please help me with that, i beak of you.
#include <stdlib.h>
#include <time.h>
void main(void)
{
int nummer0, nummer1, nummer2, nummer3,
nummer4, teller=0;
int num, i;
char tables0[10]= "1 * 2 = ";
char tables1[10]= "2 * 2 = ";
char tables2[10]= "3 * 2 = ";
char tables3[10]= "4 * 2 = ";
char tables4[10]= "5 * 2 = ";
srand((unsigned) time(NULL)); //seed random generator
for(i=0; i<5; i++){
num = rand();
num = num%5; //5 I assume number of tables
switch(num){
case 0:cout << tables0;
cin >> nummer0;
if(nummer0==2)
cout << "Goed" << endl;
else
{
cout << "Fout" << endl;
teller++;
}
break;
case 1:cout << tables1;
cin >> nummer1;
if(nummer1==4)
cout << "Goed" << endl;
else
{
cout << "Fout" << endl;
teller++;
}
break;
case 2:cout << tables2;
cin >> nummer2;
if(nummer2==6)
cout << "Goed" << endl;
else
{
cout << "Fout" << endl;
teller++;
}
break;
case 3:cout << tables3;
cin >> nummer3;
if(nummer3==8)
cout << "Goed" << endl;
else
{
cout << "Fout" << endl;
teller++;
}
break;
case 4:cout << tables4;
cin >> nummer4;
if(nummer4==10)
cout << "Goed" << endl;
else
{
cout << "Fout" << endl;
teller++;
}
break;
}
}
cout << "Aantal fouten antwoorden: " << teller << endl;
cout << "Aantal goede antwoorden: " << 5 - teller << endl;
}
Looks nice so far he!.
I only think it repeats to often the same tables, can you please help me with that, i beak of you.
about documentation ... I know there is an MSDN library online, but I don't know the link to it, so you can try to search in google.com or microsoft.com
it is really good help system
rand() generates random number from 0 to RAND_MAX
so rand()%5 will produce the number from 0 to 4
% - modulo, the remainder of division, for example
4%2 = 0
5%3 = 2
so whatever % 5 will be some number between 0 and 4
srand is to seed the random generator, think about it this way, if you don't put it, everytime you re-run the program it will be giving same random numbers
try to remove that line and run program 2-3 times, see what will happen
I think I answered everything, if other questions, ask
it is really good help system
rand() generates random number from 0 to RAND_MAX
so rand()%5 will produce the number from 0 to 4
% - modulo, the remainder of division, for example
4%2 = 0
5%3 = 2
so whatever % 5 will be some number between 0 and 4
srand is to seed the random generator, think about it this way, if you don't put it, everytime you re-run the program it will be giving same random numbers
try to remove that line and run program 2-3 times, see what will happen
I think I answered everything, if other questions, ask
ASKER
Thanks for your great help!.
if you have several tables and you want to output them in a mixed fashion I assume it isn't random.
Let's say you have two tables and you want to output the tables like this:
A[0], B[0], A[1], B[1], B[0]+B[1], A[2], B[2], B[1] + B[2], B[0] + B[1] + B[2], etc...
if A and B are two tables then you can produce that output by:
for (int i = 0; i < A_elems; ++i) {
cout << A[i] << " ";
int sum = 0;
for (int j = i; j >= 0; --j) {
sum += B[j];
cout << sum << " ";
}
cout << endl;
}
A0 B0
A1 B1 B0+B1
A2 B2 B1+B2 B0+B1+B2
A3 B3 B2+B3 B1+B2+B3 B0+B1+B2+B3
etc...
If you tell us how you plan to merge the tables, we can tell you how to do it :-)
Alf