Okay I have an array but how do I make it descending? I have it able to print out 1, 2, 3
but would rather have it do
1
2
3.
code below

#include <iostream> //Initalize Iostream
using namespace std;

void printarray(int arg[], int length) { //Print array function
for (int n = 0; n<length; ++n) // array conditons with n at default 0
cout << arg[n] << ' '; //output
cout << '\n';
}

int main()
{
int array[] = { 1, 2, 3 }; // array initalized
printarray(array, 3); // how many numbers to print in the array

}

It's quite simple: replace the trailing space, ' ', with endl (the end of line marker for ostreams). BTW, you can always use endl instead of '\n' in C++ stream output, the only difference is that endl (IIRC) also flushes the stream (that is, it forces it to go to print out immediately, rather than build up in the output buffer).

Thank you a ton :D perfect

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.