Source Code Sorting arrays first min and max and then in a ordered list from user input.

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

voila

Newbie
Full Member
Nov 18, 2013
9
124
0
Hey, i am learning c++ at the moment, i have quite a bit of testing projects.
So i made a array first min and max sorting and then in a ordered list.
Maybe if someone could tell me if i could do something better, and why i should do it that way i would appreciate it...
code:

*Note:please use code tags*

C#:
#include <iostream>
#include <string>
int MAX,MIN = 0;
using namespace std;
int main()
{
    string username[10];
    int Sort[10];
    int pancakes[10];
    int a, b;




    for(int x=0; x<=9; x++) // for loop to ask 10 questions ask for name and how many pancakes they ate,
    {
        cout << "Tell me the name of person " << x <<endl;
        cin >> username[x];
        cout<<"how much pancakes did  " << username[x] << " eat\n" << endl;
        cin >> pancakes[x];


            if(pancakes[MAX] < pancakes[x])MAX = x;
            if(pancakes[MIN] > pancakes[x])MIN = x;// checking the max and min values on eaten pancakes
    }


    cout << "The person that ate most pancakes is Person " << username[MAX] << " that ate: " << pancakes[MAX] << " pancakes\n" << "The person that ate least pancakes is Person " << username[MIN] << " that ate: " << pancakes[MIN] << " pancakes\n" << "Press any key to get the ordered list from least to most" << endl;//printing who ate most and least
    system("pause");


    for(b=0;b<=9;b++)//set array sort to a value so we can use it later
    {
        Sort[b]=b;
    }


    for(b=0; b<=8; b++)
    {
        for(a=b+1;a<=9;a++)
        {
            int temp;
            if(pancakes[Sort[b]] > pancakes[Sort[a]])// if  variable b value is greater than var a


            {
                temp = Sort[b];//assign temp to value of whatever b is
                Sort[b] = Sort[a];// taking the pancake a and puting it into pancake b
                Sort[a] = temp;// putting the value of num a as the temp. so this is where the loop becomes usefull.
            }
        }
        }
    cout << "ordered list " << endl;
    for(b=0;b<=9;b++)
    {
        cout << "Name : "<< username[Sort[b]] << " ate "<< pancakes[Sort[b]] << " pancakes" << endl;


    }
    system("pause");
}


Its working no errors but just want to see if i am heading in the right path! if my comments are right etc.
 

Liduen

Hacker
Dank Tier VIP
May 19, 2013
702
8,478
33
Well, I'm still not good at programming, but I would say this code is well written. :)
But I could not really figure out how these two for{} loops work. But this is my problem.

This example really helps when calculating which one of the enemies is closest to you and at who to aim at, when the first enemy died.
I'll need that for my aimbot ^^
 

voila

Newbie
Full Member
Nov 18, 2013
9
124
0
Well, I'm still not good at programming, but I would say this code is well written. :)
But I could not really figure out how these two for{} loops work. But this is my problem.

This example really helps when calculating which one of the enemies is closest to you and at who to aim at, when the first enemy died.
I'll need that for my aimbot ^^
Thanks, it took time for me to understand how the for loop works but i would say once you sit and maybe try 1 hour to test whats working and whats not it will make sence.
caues i was trying first to do an if statement 10 times, which isnt good and not really flexible.
So i remembered the index ordering (if its called that) its some ordering method done by a guy long time ago and i managed to write it after some hour.
Might sound redicoulous that im trying some hour on some number sorterer but i learn stuff the best that way!
ty for ur feedback :p
 

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
Bubble sort isn't the fastest method afaik.
 

Fleep

Founder
Meme Tier VIP
May 20, 2012
572
11,023
6
Bubble sort isn't the fastest method afaik.
Yh I would recommend either the quick sort or heap sort for speed.

Bubble is pretty much as slow as it gets.

Fleep
 

voila

Newbie
Full Member
Nov 18, 2013
9
124
0
Yh I would recommend either the quick sort or heap sort for speed.

Bubble is pretty much as slow as it gets.

Fleep
Oh so this is "bubble sort"
thanks for the feedback, i thought this was "index" sorting.
As i remember watching some tutorial LONG time ago on java, took the method from there.
note that i am learning c++ and i created this without watching any tutorial..
Apprecheate your feedback
Can you tell me the logic behind quick sort? like i dont want any code or something..
But if i google "quick sort" i will get the code, so thanks if u wanna tell me.
 

xPaay

Newbie
Jun 26, 2013
1
152
0
There's no best sorting algorithm. Every algorithm is better then others on some cases. This site has some good animations with the most used sorting algorithm.

https://www.sorting-algorithms.com/

Btw I've got a schoolwork where I needed to get the time to sort a 1 million+ vector in three different cases and with at least 4 sorting algorithm. In my case bubblesort was the worse on most cases, but in one specific test, quicksort was slower then bubble.
 

Syperus

RTFM
Meme Tier VIP
Dank Tier Donator
Oct 29, 2012
432
2,638
7
I would also change system("pause") to std::cin.get() so it can be used on multiple OS's. Irregardless of what method you use it was a good learning exercise I'm sure. :)
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods