output
-
I have 2 arrays and I need to display data this way: array1 array2 data1 data1 data2 data2 data3 data3 How do I dot this?
for (int x = 0; x < 2; x++)
<< ' ' << array2[x] << endl;
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
I have 2 arrays and I need to display data this way: array1 array2 data1 data1 data2 data2 data3 data3 How do I dot this?
IT depends - if you know they are the same length, and know what that length is, you can do this (using "cout" as an example, you can use print, or do it to a list box, or whatever.)
cout << "Array 1\t\tArray 2" << endl; for(int i = 0; i < sizeOfArrays; i++) { cout << array1[i] << "\t\t" << array2[i] << endl; }
Now, if your array sizes are different, it's tricker. You either need array classes (e.g., CArray or stl::vector), or variables specifying the size of each array, and then in the for loop, check to make sure you're not out of bounds, e.g. (assuming array1 and array2 are STL vectors):cout << "Array 1\t\tArray 2" << endl; int arraySize = array1.size(); if(array2.size() > arraySize) arraySize = array2.size(); for(int i = 0; i < arraySize; i++) { if(i < array1.size()) cout << array1[i] << "\t\t"; else cout << "(null)\t\t"; if(i < array2.size()) cout << array2[i] << endl; else cout << "(null)" << endl; }
You can tweak the formatting as necessary. If your nose runs and your feet smell, then you're built upside down.
-
I have 2 arrays and I need to display data this way: array1 array2 data1 data1 data2 data2 data3 data3 How do I dot this?
Ugh, this smells like homework. :suss: /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com
-
IT depends - if you know they are the same length, and know what that length is, you can do this (using "cout" as an example, you can use print, or do it to a list box, or whatever.)
cout << "Array 1\t\tArray 2" << endl; for(int i = 0; i < sizeOfArrays; i++) { cout << array1[i] << "\t\t" << array2[i] << endl; }
Now, if your array sizes are different, it's tricker. You either need array classes (e.g., CArray or stl::vector), or variables specifying the size of each array, and then in the for loop, check to make sure you're not out of bounds, e.g. (assuming array1 and array2 are STL vectors):cout << "Array 1\t\tArray 2" << endl; int arraySize = array1.size(); if(array2.size() > arraySize) arraySize = array2.size(); for(int i = 0; i < arraySize; i++) { if(i < array1.size()) cout << array1[i] << "\t\t"; else cout << "(null)\t\t"; if(i < array2.size()) cout << array2[i] << endl; else cout << "(null)" << endl; }
You can tweak the formatting as necessary. If your nose runs and your feet smell, then you're built upside down.