| | |
Parrallel array problem
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 34
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; const int capacity = 20; string tax_payers[capacity] = {"jane", "tom", "jerry", "joe", "annie", "mary", "kate", "steve", "sarah", "paul", "petra", "peter","elaine", "noreen", "sean", "niamh", "donal", "john", "marie", "colin"}; double income[capacity] = {21000.0, 16500.0, 120000.0, 16000.0, 38000.0, 62500.0, 14500.0, 28500.0, 13500.0, 27500.0, 15000.0, 44000.0, 18000.0, 21000.0, 150000.0, 15500.0, 40000.0, 21000.0, 25000.0, 37500.0}; void swap(int &j, int &k); int spaces = 25; int main() { cout << "\t" << "Sorted list" << endl; for (int j = 0; j < capacity-1; j++) for(int i = 0; i < capacity-1; i++) { if (income[i] < income[i+1]) swap(income[i],income[i+1]); } for(int i = 0; i < capacity; i++) cout << "\t" << tax_payers[i] <<" " << "\t" << income[i] << endl;; cout << "\n"; cout << "\t" << "Under 25000"<< endl; for(int i=0;i<capacity;i++) { if(income[i] < 25000) cout << "\t"<< tax_payers[i] << "\n "; } cout << "\n"; cout << "\t" << "Over 25000" << endl; for(int i=0;i<capacity;i++) { if(income[i] > 25000) cout << "\t" << tax_payers[i] << "\n "; } return 0; } void swap( int &j, int &k ) { int tmp = j; j = k; k = tmp; }
Sorry bout early post, went wrong my bad. I jst need help to assign the right tax payer and income to the right person for example sean shud b 150000 and not jane, she shud b assigned 21000. Any ideas why it is doin that??
Last edited by Narue; Jul 16th, 2008 at 2:44 pm. Reason: Fixed code tags
I haven't read all of your code because it is hard to read wihtout code tag. However, I think your sort should be in this way:
When you sort your income array, the oringinal order of income will probally be changed. To keep it parrallel to the tax payers, you need to change the tax payers order too.
C++ Syntax (Toggle Plain Text)
string temp; for (int j = 0; j < capacity-1; j++) { for(int i = 0; i < capacity-1; i++) { if (income[i] < income[i+1]) { swap(income[i],income[i+1]); temp = tax_payers[i]; tax_payers[i] = tax_payers[i+1]; tax_payers[i+1] = temp; } } }
Last edited by invisal; Jul 16th, 2008 at 2:46 pm.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Behind every smile is a tear.
Visal .In
![]() |
Similar Threads
- help passing parrallel arrays to functions (C++)
- Input problem using arrays (C++)
- Strings, parrallel arrays, storing data c++ (C++)
- help with parrallel arrays (C++)
Other Threads in the C++ Forum
- Previous Thread: Exception in Visual C++
- Next Thread: C++ awesomest book?
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





