Welcome to the world of spoiled programmers.
One piece of advise, we don't talk to vi and emacs users. They are a bunch of conceited brats.
Welcome to the world of spoiled programmers.
One piece of advise, we don't talk to vi and emacs users. They are a bunch of conceited brats.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Nano all the way!! By the way, I use Code::Blocks, which is another great Windows IDE (Dev-C++ died one me )
I'm gonna spend the next few late nights at my computer using Dev-C++ deffinitely!!...
Okay,... so I think i'm slightly getting there. Here's the code I adjusted.But I got something which looks like thisCode:int main(void) { int numbers[10]; std::cout << "Enter 10 grades: "; for (int i = 1; i < 10; i++) std::cin >> numbers[i]; bubbleSort(numbers, 10); std::cout << "Your sorted grades are: " ; for (int k = 1; k < 10; k++) std::cout << numbers[k]; return 0; } ... ...
Last edited by [Z-D]; 11-28-2006 at 07:28 PM.
First, you want to set i to 0, otherwise you're jumping over the first index which would expect a bit of the junk you have on the screen. Same thing for k. I honestly don't see anything right now... Huhhh.. Try changing what I told you and tell us if it worked ok.
You mean this right?:Originally Posted by DesolationSame thing happens.Code:#include <iostream> #include<iomanip> void bubbleSort(int numbers[], int array_size); int main(void) { int numbers[10]; std::cout << "Type down the 10 grades and press enter after each grade:\n"; for (int i = 0; i < 10; i++) { std::cin >> numbers[i]; } bubbleSort(numbers, 10); std::cout << "\n\nYour sorted grades are:\n" ; for (int k = 0; k < 10; k++) { std::cout << numbers[k] << ", "; } std::cout << "\n\n"; return 0; } void bubbleSort(int numbers[], int array_size) { int i, j, grades; for (i = (array_size -1); i >= 1; i--) { for (j = 1; j <=i; j++) { if (numbers[j-1] > numbers[j]) { grades = numbers[j-i]; numbers[j-1] = numbers [j]; numbers[j] = grades; } } } }
Try
Or if you like, try using std::vector for the arrays.Code:void bubbleSort(int &numbers, int array_size)
Your bubblesort function needs to go to 0 too.
Arrays in C are indexed from 0 to n-1. So, if you have an array of length 8, your indexes will be 0, 1, 2, 3, 4, 5, 6 and 7. So, bubblesort also needs to go down to 0.Code:void bubbleSort(int numbers[], int array_size) { int i, j, grades; for (i = (array_size -1); i >= 0; i--) { for (j = 1; j <=i; j++) { if (numbers[j-1] > numbers[j]) { grades = numbers[j-i]; numbers[j-1] = numbers [j]; numbers[j] = grades; } } } }
This one just give me more errors... Or do I have to change the rest also?...Originally Posted by g4j31a5
How to use that?...Originally Posted by g4j31a5Didn't work... after inputing the last integer, the whole thing just closes. That is in Dev-C++.Originally Posted by Sfel
The funny thing is the result in MV-C++, and Dev-C++ is slightly different. Is that normal?
I think :
should be:Code:grades = numbers[j-i]; numbers[j-1] = numbers [j];
Code:grades = numbers[j-1]; numbers[j-1] = numbers [j];
ZD, you really have to stop there. Stop for a moment take a deep breath and read on...
You cannot post every time you get stuck with a problem. Part of the learning process is to look for answers yourself. And no, that doesn't mean just asking.
You have already been told about the tutorials.
If you read how to use these things then you will learn how to use them and all problems will magically go away.
I understand it is a C++ test and all. But your aren't in school to just watch. There is a real intent of having you learn about things. And learn you should without trying to thwart it's meaning.
Read the tutorials for arrays. Read the tutorials for vectors. Read the basic tutorials that introduce you to the for loop.
Read, learn and then post your questions, if you still have any, without leaving the lasting impression you aren't really giving too much effort to this, and instead forcing others to teach you.
The tutorials are here: http://www.cprogramming.com/tutorial.html
Scroll that page and be amazed at what others have made available already. Be a chum and don't make them feel they have wasted their time explaining things.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Then I guess you're saying that i'm asking for too much.... I undestand, but it wasn't really neccesary for you to UNDERLINE, READ and LEARN as if I never thought of any of that.
I have been reading tutorials here and there. But I just can't seem to get it right and I didn't have Dev-C++ (now I do ofcourse). So that's why I decided to post here.
I mean, this is my first attempt on using arrays... This thread started with me not knowing almost anything about arrays.
Well okay then. I'll slow down my posts. But, I'm really getting worried. Thanks you all anyway.
He didn't mean to hurt you. When you have a programming problem, use google and find tutorials on the topic you are having troubles with. If your compiler outputs an error message you don't understand, copy and paste that error message in google and chances are that you might find the meaning of the message. Also, don't take what the users on forums tell you as 100% correct. Someone pointed you to do this:
void bubbleSort(int &numbers, int array_size)
How could that be correct ? A reference to an integer... you are passing in an array. This cannot be correct.
I think Stiopa has the answer to your problem though.
I'm not hurt,... everything is cool. And I get you guys.... I understand I mean.Originally Posted by DesolationSo now I know that my Dev-C++ actually isn't working properly, I had no time to get it right cause I had to go to sleep, Now I'm at my com lab testing my code!... So I adjusted this...Originally Posted by Stiopa
And guess what!?... It's working!!!!!! I don't know what to do now. Should I cry or what?
Thank you all guys!!... Now I'm gonna do more practicing with arrays and try to ask less repetitive questions.
Wait.. you mean you used the same code with the proper modifications, thus getting rid of the bug, and then it worked ? And then you're saying Dev-C++ doesn't work ? Let me tell you, it IS working. I used that IDE for years and you know what ? It works.
My mistake. What I really wanted to say wasOriginally Posted by Desolation
void bubbleSort(int *numbers, int array_size)
But then again, it's practically the same with "int numbers[]". I was at the last minutes in the office so my head was so full. Couldn't think straight. I even saw the:
asgrades = numbers[j-i];
Sorry couldn't be of any help.grades = numbers[j-1];