• ### Question

• I'm new to the programming world. I'm currently going to college for game software development and I'm in my 8th week of my fundamentals of programming class. I would normally go to my instructor, but her responses aren't always quick. Anyways, I'm in need of someone who can explain to me how to do the following:

Individual assignment:

When developing more difficult programs, it is important for us to take an incremental approach. We start by developing the simplest program and then we make small modifications to it until it evolves into our final result. Try to keep a functional program at all times.

First, write a simple program that will read 5 numbers from the Console (user input).  Store these values into an array of int [].  Using the length of the array in a for() loop and decrementing the loop counter, write the array values in reverse order to the screen.   This is step one and may be enough for partial credit. If you have difficulty with this, try seeking some assistance from your instructor before going on to step two.

Next, add code to read 5 words from the Console (user input).  Store these values into an array of string [].  Make sure the string[] array is large enough to hold at least 6 values. Store the string constant “end_of_array” into the last element of the array. Using a do…while() loop, print out the 1st and 3rd letters of each word (two letters per line) using the substring function.  This is step two and should ensure you at least a passing grade.

I know how to get the numbers from the console, what I am lost with is how to get them to be stored in an array, or how to use the length of the array in a for() loop for that matter. Even more confusing is how to get it to spit the numbers back out in reverse order. Any help will be greatly appreciated.

I am using VS C++ Express edition. I hope that some one can help me and explain all this to me so I can get my head wrapped around it and stop feeling like a bone head. Thanks in advance!

I also want to say that this is online classes, so staying after to get help from the instructor is kind of out of the question.

StatWC

Friday, July 18, 2008 9:16 PM

• >>what I am lost with is how to get them to be stored in an array

Review these subjects:

Lesson 8: Array basics
http://www.cprogramming.com/tutorial/lesson8.html

Lesson 8: Arrays
http://www.cprogramming.com/tutorial/c/lesson8.html

A Tutorial on Pointers and Arrays in C
http://cpp.snippets.org/code/ptrtutor.txt

- Wayne

• Marked as answer by Wednesday, July 23, 2008 3:51 AM
Saturday, July 19, 2008 8:29 PM
• How are you getting on with your assignment? Here is something to get you started if you still need help

#include <iostream>
using namespace std;
const int n = 5;
int main (void)
{
// Create array of numbers
int array[n];
cout << "Give " << n << " numbers:" << endl;
for(int i = 0; i < n ; i++)
{
cin >> array[i];
}
// Write array to the screen
cout << "Array in reverse order:" << endl;
for(i = n-1; i >= 0; i--)
{
cout << array[i] << " ";
}
cin.ignore(1000,'\n').ignore(1000,'\n');
return 0;
}
• Marked as answer by Wednesday, July 23, 2008 3:52 AM
Tuesday, July 22, 2008 12:36 PM

### All replies

• Well, you don't seem to think much about your teacher but she came up with an excellent assignment to test your ability to absorb what she tried to teach you.  The notion of storing values in an array is quite fundamental to programming.  Eight weeks of training should have prepped you well to understand the most basic of collection objects.

I could give you the answer, but then I'd risk having to teach you these fundamentals when you graduated, with our help, and came to work at my company.  Just as you don't appreciate your teacher much, you probably wouldn't think much of me either.  And I would return the favor.  I think I could avoid all these complications and simply not hire you.  I'd use the same test.

Hans Passant.
Friday, July 18, 2008 9:43 PM
Saturday, July 19, 2008 12:29 AM

• >>what I am lost with is how to get them to be stored in an array

Review these subjects:

Lesson 8: Array basics
http://www.cprogramming.com/tutorial/lesson8.html

Lesson 8: Arrays
http://www.cprogramming.com/tutorial/c/lesson8.html

A Tutorial on Pointers and Arrays in C
http://cpp.snippets.org/code/ptrtutor.txt

- Wayne

• Marked as answer by Wednesday, July 23, 2008 3:51 AM
Saturday, July 19, 2008 8:29 PM

-Wayne, thank you for at least attempting to help me get a better understanding of what I'm supposed to be doing. Your response is the reason I came here with my questions and problems.
• Edited by Monday, July 21, 2008 6:18 PM spelling
Monday, July 21, 2008 6:16 PM
• StatWC:

People here will not do your homework for you. The way it works is you post your code, and hopefully someone will help you with why it is not working.

David Wilkinson | Visual C++ MVP
Monday, July 21, 2008 7:02 PM
• How long is your total formation in Game Software Developpement StatWC??
Monday, July 21, 2008 7:07 PM
• Eric,

If you are asking how long have I been at this, the answer is 8 weeks. I just started. I have 3 whole more years to go. If I could have found a good school near me that offered the classes and degree I am going for I would have gone on campus.

davewilk,

I'm sorry if it seemed like I was asking people to do my assignments for me. That is not the case. Actually Wayne gave me the most help by directing me to a tutorial that better explained to me how arrays and strings worked. That was what I came here looking for. a better understanding of how it worked. I can do the assignment. i was just at odds with how it was supposed to work in the first place. I should have worded what I was asking better.
• Edited by Monday, July 21, 2008 8:57 PM spelling
Monday, July 21, 2008 8:56 PM
• How are you getting on with your assignment? Here is something to get you started if you still need help

#include <iostream>
using namespace std;
const int n = 5;
int main (void)
{
// Create array of numbers
int array[n];
cout << "Give " << n << " numbers:" << endl;
for(int i = 0; i < n ; i++)
{
cin >> array[i];
}
// Write array to the screen
cout << "Array in reverse order:" << endl;
for(i = n-1; i >= 0; i--)
{
cout << array[i] << " ";
}
cin.ignore(1000,'\n').ignore(1000,'\n');
return 0;
}
• Marked as answer by Wednesday, July 23, 2008 3:52 AM
Tuesday, July 22, 2008 12:36 PM