Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
integer array with a bubble sort c++
Old 12-10-2008, 09:35 PM integer array with a bubble sort c++
Junior Talker

Posts: 3
Trades: 0
Hey all so im working on this project and ran into some problems and could use some help. The project is split into functions with a single file project. Their is a menu that display the user enters a choic and then goes to the entered area, their is a add person which adds a name and $amount. then a view option to display what was entered and then a sort option using a bubble sort. So i know i have problems with my code but im not sure where. Any help would be greatly appriciated.

Code:

//searches.cpp
#include<iostream>
#include<string>
usingnamespace std;
int displayMenu(void);
void processChoice(int); //missing argument
void Add(string, int);
void View(string, int);
//sort list
int main()
{
int num;
do
{
num=displayMenu();
if (num !=4)
processChoice(num);
}
while (num !=4);
return 0;
}
int displayMenu (void)
{
int choice;
cout <<
"\nMenu\n";
cout <<
"==============================\n\n";
cout <<
"1. Add student to waiting list\n";
cout <<
"2. View waiting list\n";
cout <<
"3. Sort list\n";
cout <<
"4. Exit program\n\n";
cout <<
"Please enter choice: ";
cin >> choice;
return choice;
}
void processChoice(int choice)
{
switch (choice)
{
case 1: Add();//(string, int);
break;
case 2: View();//(string, int);
break;
//case 3: Sort(); break;
}
}
void Add(string n[], int b[])
{
for (int j = 0; j<5; j++)
{
cout <<
"Enter students name\n ";
cin>>n[j];
}
for (int x = 0; x<5; x++)
{
cout<<
"Enter bribe amount\n ";
cin>>b[x];
}
}
void View(string nam[], int brib[])
{
for (int i=1; i<5; i++)
{
cout<<i<<
" "<<nam[]<<" $"<<brib[]<<endl;}
}
//sort stuff will go here

tchspy5 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-12-2008, 06:00 AM Re: integer array with a bubble sort c++
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
The first thing I see right away is that you arn't indexing your array in the View function. nam[] should be nam[x] where x is an intenger > 0. In this case it looks like you want to index your array using i in your for loop.

Could you please post the error message you are getting. Also you may want to format your code. You need some tabs and spaces.

Code:
cout<<i<<" "<<nam[]<<" $"<<brib[]<<endl;

should be

cout << i << " " << nam[i] << " $" << brib[i] << endl;
Function and method names should not start with a capital letter. Only the words in a function name after the first should be capitalized: functionName not FunctionName or functionname.

One more thing. Is there any particular reason why you are using bubble sort? As far as I know bubble sort exists only as an example of how not to sort data. There are sorts that are just as easy to code that perform much better and you should learn those in place of bubble sort. Try insert sort to begin with.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 12-12-2008 at 06:02 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 12-17-2008, 11:11 PM Re: integer array with a bubble sort c++
anderswc's Avatar
Super Talker

Posts: 132
Name: Will Anderson
Location: Terre Haute, IN
Trades: 0
echo NullPointer. Bubble Sort is one of the slowest sorting algorithms.
Check out something like insertion sort if you want something simple, but a little more efficient (though certainly not the most efficient!)
__________________
Will Anderson

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
anderswc is offline
Reply With Quote
View Public Profile Visit anderswc's homepage!
 
Reply     « Reply to integer array with a bubble sort c++
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30129 seconds with 12 queries