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.





alexanderthegreatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SalteCommented:
Not sure what your question is but here goes..

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
0
alexanderthegreatAuthor Commented:
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.






0
GulaCommented:
>>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
}
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

alexanderthegreatAuthor Commented:
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.


0
GulaCommented:
this will display it in random order, but the line may repeat

#include <iostream.h>
#include <stdlib.h>
#include <time.h>
void main(void){
     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 <<'\n';break;
               case 1:cout << tables1 <<'\n';break;
               case 2:cout << tables2 <<'\n';break;
               case 3:cout << tables3 <<'\n';break;
               case 4:cout << tables4 <<'\n';break;
          }
     }
     
}

I'm afraid this is a homework, that's why I don't want to give you the whole solution..
if you don't want the lines to repeat, you should think about the way to do it.. say... you could create an array that will keep which num has been called already, or maybe you can come up with some other solution..
try it, and if you cannot do it, post what you have tried, and we will solve it together
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alexanderthegreatAuthor Commented:
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.



0
alexanderthegreatAuthor Commented:
#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.
0
GulaCommented:
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
0
alexanderthegreatAuthor Commented:
Thanks for your great help!.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.