•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,865 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,649 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 203 | Replies: 4 | Solved
![]() |
•
•
Join Date: Apr 2008
Posts: 22
Reputation:
Rep Power: 1
Solved Threads: 0
cplusplus 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
•
•
Join Date: Mar 2005
Location: Phnom Penh, Cambodia
Posts: 415
Reputation:
Rep Power: 5
Solved Threads: 36
•
•
Join Date: Mar 2005
Location: Phnom Penh, Cambodia
Posts: 415
Reputation:
Rep Power: 5
Solved Threads: 36
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.
cplusplus 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
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- 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?


Linear Mode