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?
"Without using an array" - Does that mean you're OK to use a linked list or a binary tree? (or a Standard Library container?)
Or do you mean that you're trying to sort a series of numbers at the time they're input without storing them in any kind of container/list/tree/etc? If its the latter, then the only reasonable way to do it would be recursion.
In this case you could simply use a list and use iterators to determine where you need to insert your element? Then, once the list is formed you just iterate over it and count tens.
Edit: Check out this reference: http://www.cplusplus.com/reference/stl/list/
#include <iostream>
usingnamespace 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;
}