We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,390 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

C++ Sorting with Loops

I need to sort a series of 25 numbers, entered by the user from smallest to largest, then count the number of times the user entered the number "10". I can't use arrays and I have to use only for loops, can someone please help?

4
Contributors
5
Replies
5 Hours
Discussion Span
1 Year Ago
Last Updated
6
Views
Question
Answered
free2move
Newbie Poster
3 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

When you say you "can't use arrays", what exactly does that mean? Because it's quite impossible to sort anything when you can't retain it, and while you can use 25 variables to get the same effect as an array, that's totally insane. I can't imagine a teacher expecting you to do that unless they subscribe to the school of hard knocks and want to teach you the importance of arrays.

deceptikon
Challenge Accepted
Administrator
3,457 posts since Jan 2012
Reputation Points: 822
Solved Threads: 474
Skill Endorsements: 57

If you can't use arrays, did you set up your 26 (or 27) variables, yet?

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

You can't use arrays? Can you use linked lists or trees?
EDIT: How did we all reply at the same time?

DeanMSands3
Posting Whiz
310 posts since Jan 2012
Reputation Points: 80
Solved Threads: 42
Skill Endorsements: 1

well I can't use an array set up like "array[45]" the user just needs to enter 25 integers and the program needs to sort it and print the number of times the number "10" is printed.

free2move
Newbie Poster
3 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

never mind, i overestimated it.

#include <iostream>
using namespace std;

int main()
{
	int max;
	int min;
	int ten=0;
	int total;
	int i;
	cout << "Please Enter a number" << endl;
	cin >> max;

	min=max;
	total=max;

	if (max==10)
		ten++;
	for (int x=1; x<25; x++)
	{
		cout << "Please Enter a number" << endl;
		cin >> i;

		if (i>max)
			max=i;
		if (i<min)
			min=i;
		if (i==10)
			ten++;
		total += i;
	}
	cout << "Max =  " << max << endl << "Min =  " << min << endl << "There were  " << ten << " 'tens' entered" << endl; 
	
}
free2move
Newbie Poster
3 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by DeanMSands3, deceptikon and thines01

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0968 seconds using 2.85MB