Struggling with end of array for program
| gem925 (14) | |||
| 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. Any guidance would be greatly appreciated. | |||
| guestgulkan (232) | |||
| What have you done so far?? | |||
| gem925 (14) | |||
| This is what I have done far: //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. #include <iostream> #include <string> using namespace std; int main() { int array[5]; int counter; int i = 0; int string[6]; char word; cout << "Please enter five numbers: "; for (counter = 0; counter < 5; counter++) { cin >> array[counter]; } cout << endl; cout << "Counting down the numbers: "; for(counter = 0; counter < 5; counter = counter++) cout << array[counter] << " "; cout << endl; cout << "The numbers in reverse order are: "; for (counter = 4; counter >= 0; counter--) cout << array[counter] << " "; cout << endl; //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. cout << "Please enter five words: "; for (counter = 0; counter < 6; counter++) { cin >> string[counter]; } cout << endl; do { cout << "Print out 1st letter for each word: " << string << endl; }while( return 0; } | |||
| guestgulkan (232) | |||
A quick solution in the spirit of your original code;
| |||
| gem925 (14) | |||
| Thank you so much for your help I just wish the book would show examples like this so I could understand it better. | |||
This topic is archived - New replies not allowed.
