?
Solved

mixing tables

Posted on 2003-02-21
9
Medium Priority
?
316 Views
Last Modified: 2010-04-01
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.





0
Comment
Question by:alexanderthegreat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 12

Expert Comment

by:Salte
ID: 7993420
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
 

Author Comment

by:alexanderthegreat
ID: 7993757
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
 
LVL 1

Expert Comment

by:Gula
ID: 7993820
>>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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:alexanderthegreat
ID: 7993922
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
 
LVL 1

Accepted Solution

by:
Gula earned 80 total points
ID: 7994005
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
 

Author Comment

by:alexanderthegreat
ID: 7994191
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
 

Author Comment

by:alexanderthegreat
ID: 7994375
#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
 
LVL 1

Expert Comment

by:Gula
ID: 7994412
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
 

Author Comment

by:alexanderthegreat
ID: 7998182
Thanks for your great help!.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question