C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 30th, 2013, 05:25 AM
SixTsevN SixTsevN is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 SixTsevN User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 45 sec
Reputation Power: 0
Selection Sorter

Hey there,
I'm trying to write a program that takes ten values from the user and sorts them in ascending order.

I can't get the loop that actually sorts them into order to work.
It's been driving me crazy for 3 days.

Here is my source code(Hopefully you can understand what I'm trying to do):

#include <iostream>
using namespace std;

int main()
{
//Main declarations
int list[10];
int sort[10];
int inc = 0;
int min = 0;

//Function to receive values from user
cout << "Enter ten random integers to sort " << endl;
for(int cnt = 0; cnt < 10; ++cnt)
{
cout << "[" << cnt+1 << "]: ";
cin >> list[cnt];
}
cout << endl;

//Displaying unsorted list
cout << "Unsorted list = " << endl;
for(int cnt = 0; cnt < 10; ++cnt)
{
cout << list[cnt];
if(!(cnt == 9))
{
cout << ", ";
}
}
cout << endl;

//Finding minimum value
cout << "Sorting..." << endl;
for(int cnt = 0; cnt < 10; cnt++)
{
if(list[min] >= list[cnt])
{
min = cnt;
}
}
sort[0] = list[min];
inc++;
min = 0;

//Sorting remaining values in ascending order, using minimum as margin (here is the problem)
for(;inc < 10; inc++)
{
for(int cnt = 0; cnt < 10; cnt++)
{
if(sort[inc] <= list[cnt] && list[min] >= list[cnt])
{
min = cnt;
}
if(cnt == 10)
{
sort[inc] = list[min];
min = 0;
}
}
}

//Display sorted list (unfinished coding)
cout << "inc = " << inc << endl;
for(int cnt = 0; cnt < 10; cnt++)
{
cout << sort[cnt] << endl;
}
system("pause");
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Selection Sorter


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap