If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Strings & Arrays

I am trying to write a program that Store 5 numbers 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. Thats the easy part This is were i am having issues 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. Can someone please help out.

// Line 15 user inputs 5 words
// Line 18 int set to 0 and will count 1 until it hits 5 Arrays
// Line 28 the first [0] is the string 2nd [2] is how many letters it is going to count
// Line 24-32 Running the do while loop that has to access the Array Boxes
// Line 34 End_of_Array when the expression is true
const char* END_OF_ARRAY = "end_of_array";

> // Line 28 the first [0] is the string 2nd [2] is how many letters it is going to count

oh, no!. i presume that this is the line you are referring to:

Code:

cout << theArray[counter][0] << theArray[counter][2] << "\n" ;

here, theArray[counter] is the string (at position counter in the array)
theArray[counter][0] is the first char in that string (at position 0).
and theArray[counter][2] is the third char in that string (at position 2).

and to send a single char to a stream, use << '\n' (instead of << "\n"). it is more efficient.

Advertiser Disclosure:
Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.