Read numbers

Use a one-dimensional array to solve the following problem: Read in 20 numbers between 10
and 100 inclusive. As each number is read, validate it (be sure to be between 10 and 100) and
store it in the array only if it is not a duplicate of a number already read.
After reading all the values, display only the unique values that the user entered.
Sort the array using bubble sort and display the sorted array.


I have one question about this, how do I "read" numbers without using an array?
You can use a variable where you store the number you read. Then you validate the number and, if it's ok, you store it in your array.
rjghoul wrote:
I have one question about this, how do I "read" numbers without using an array?


then you need 20 variables a,b,c.....
or if you don't call this
std::vector<int>v
an array you can use this.
Actually the first post is a bit strange: the text says
Use a one-dimensional array
but then he says
without using an array
I thought it might be a typing error.
Last edited on
store it in the array only if it is not a duplicate of a number already read.
After reading all the values, display only the unique values that the user entered.

isn't the second sentence redundant?
if only non duplicates are stored,wouldn't the whole array be filled with unique numbers?
Last edited on
the OP cant use <set> for restrictions.
but,
1
2
3
4
5
 std::set<int> mySet;
mySet.insert(5);
mySet.insert(8);
mySet.insert(4);
mySet.insert(5);


mySet contains only unique members sorted {4,5,8}

the OP cant use <set> for restrictions

Probably they are at the beginning of a C++ course and have not studied STL yet...
Topic archived. No new replies allowed.