Help with homework and i have no idea where to start.

I am seriously confused with my homework ever since we started adding loops to the party. What i have to do is prompt the user for how many numbers they are going to input. Then enter in how many of those random numbers the user decides to enter. A loop has to be used to read the random numbers typed and give a report like how many zeros were used, or how many odd and even numbers and the range of the numbers entered. Heres an example of what an output would look like.

Enter how many numbers you plan on entering: 6
please enter 6 integers
0 12 67 3 10 9
You have entered: 1 zero, 2 even numbers 3 odd numbers and the range of your input is 0 to 67.

or How many numbers do you plan on entering: 3
please enter 3 integers
d 5 p
invalid. please enter 3 integers


I know i have two options to use a for loop or a do while loop. When in a help session, i was told to use an array but i dont even know what that is.



Im not asking for answers just pointers or a little help
Thank you for your time
OK for help loops I suggest checking out: http://www.cplusplus.com/doc/tutorial/control/

Arrays are one of the simplest data structures(a way of storing data) and you can find more here: http://www.cplusplus.com/doc/tutorial/arrays/

For this problem, it would be more appropriate to use a vector because of the undecided size until the user enters the number of numbers. It can be done with an array but you will have to limit the number of numbers that the user will be able to enter. Vectors are dynamic (can change) and arrays are static(can't change in size).

Start working on the parts you do know.
Just like joe said. Its really simple if you can use vectors

1
2
3
4
5
6
7
8
9
10
11
12
13
vector<int> intVector;

int numNumbers;
cout << "How many Numbers?" << endl;
cin >> numNumbers;

int userNum;
for(int i = 0; i < numNumbers; i++)
{
    cout << "Please enter number << (i + 1) << endl;
    cin >>  userNum;
    intVector.push_back(userNum)
} 
Last edited on
Topic archived. No new replies allowed.