1,105,534 Community Members

C++ Sorting with Loops

Member Avatar
free2move
Newbie Poster
3 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

Member Avatar
deceptikon
Eternally Awesome
4,689 posts since Jan 2012
Reputation Points: 1,341 [?]
Q&As Helped to Solve: 688 [?]
Skill Endorsements: 104 [?]
Administrator
Featured
 
-2
 

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.

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
0
 

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

Member Avatar
DeanMSands3
Posting Whiz
358 posts since Jan 2012
Reputation Points: 57 [?]
Q&As Helped to Solve: 49 [?]
Skill Endorsements: 2 [?]
 
0
 

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

Member Avatar
free2move
Newbie Poster
3 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
free2move
Newbie Poster
3 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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; 
	
}
Question Answered as of 2 Years Ago by thines01, DeanMSands3 and deceptikon
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: