Read numbers

Jan 7, 2015 at 9:01am
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?
Jan 7, 2015 at 10:23am
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.
Jan 7, 2015 at 3:42pm
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.
Jan 7, 2015 at 7:31pm
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 Jan 7, 2015 at 7:32pm
Jan 8, 2015 at 12:17am
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 Jan 8, 2015 at 12:18am
Jan 8, 2015 at 7:05am
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}
Jan 8, 2015 at 7:10am

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.