Arrays

hi. i have been having a hard time trying to use arrays on my program :/


im supposed to create a program that will accept no. for the last loop then display the 3rd highest data, display the input data, and the reverse of the data from last input to first input.



this is only what i have and i dont know where to start
someone help me? :/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;
int main()
{
    int no,a,in;
    
    a=0;
    cout<<"Enter number for the last loop: \n";
    cin>>no;
        
    while(a<no)
    {
                cout<<"Enter a number:\n";
                cin>>in;
                a++;
                }
    



system("pause");
}
Last edited on
closed account (o3hC5Di1)
Hi there,

Well, you probably will need to declare at least one array in your code - which you have not done so far.
I would advise you to go over this section of the tutorial on this site:
http://cplusplus.com/doc/tutorial/arrays/

Basically you will have to define an array, then you can use for-loops to traverse the array and perform reading / writing operations on it.

Let us know if you have any further questions after reading that part of the tutorial.

Hope that helps.

All the best,
NwN
Last edited on
Thank you NwN. I tried to read the link that you gave to me but my mind is out of nowhere, but it would still help me later on i guess. :)
closed account (o3hC5Di1)
What part are you finding hard to understand?
Don't reply "all of it", try to think of specific things.

It's usually those specific things that hold you back from understanding the whole concept.

All the best,
NwN
I don't think that reverses the array...

here, this reverses it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

int main()
{
    int original[10]= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    int reversed[10];

    for (int i = 0; i < 10; i++)
    {
        reversed[i] = original[9-i];
        std::cout << "[" << i << "]" << original[i] << "/" << reversed[i] << std::endl;
    }

    return 0;
}
Last edited on
Topic archived. No new replies allowed.