1.11M Members

C++ Sorting with Loops

 
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?

 
-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.

 
0
 

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

 
0
 

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

 
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.

 
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: