C++/dev c++


i am a student trying to learn dev c++ and i am having trouble making a program. the program description is Write a C++ program that asks the user to enter 6 numbers separated with spaces
and then prints out the entered numbers in reverse order. A sample output is shown
Enter 6 numbers: 2 5 7 1 8 9
The reverse is : 9 8 1 7 5 2
Your program should use 2 for loops, an array and a const int called ARRAYSIZE.
i am having trouble creating the for loop to reverse the numbers..

first declare an array that can hold six numbers

enum { ARRAYSIZE = 6 } ;
int numbers[ARRAYSIZE] ;

then, write a loop that iterates through array indices starting at 0 and ending at ARRAYSIZE-1. in the loop, accept the number and store it in the array.

to print out the numbers in reverse, write a loop that iterates through array indices starting at ARRAYSIZE-1 and ending at 0. in the loop, print out the number at the particular index in the array.

for( int i = ARRAYSIZE-1 ; i >= 0 ; --i )
       // TODO: print out the number at numbers[i] here

note: dev c++ is just an IDE (a development environment). the compiler you are using is some version of the GNU C++ compiler (g++). and what you are trying to learn is programming in the C++ programming language. so the code that you write is specific to C++ (you could use any conforming C++ compiler to compile it, and you may use any suitable IDE.)  


All Answers

Answers by Expert:

Ask Experts




my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.


about 15 years or so

post graduate engineer

©2017 About.com. All rights reserved.

[an error occurred while processing this directive]