Hello I am taking a programming class and I am stuck with this part of the project. Could someone please help me out. Below is the portion I am stuck on and below that is the current code I have completed.
• Then, write the code to update every other element within the array with a lowercase x. The output should appear like the following:
PRINTING CONTENTS OF ARRAY and adding x to every other element
A x C x E x G x I x K x M x O x Q x S x U x W x Y x
• Write the code that will display only the even or odd numbered elements within the array. The output should appear as follows:
PRINTING CONTENTS OF ARRAY USING THE MOD Option
=====================================================
Even Numbered Element = 0 Contents of Element within Array is = A
Even Numbered Element = 2 Contents of Element within Array is = C
Even Numbered Element = 4 Contents of Element within Array is = E
Even Numbered Element = 6 Contents of Element within Array is = G
Even Numbered Element = 8 Contents of Element within Array is = I
Even Numbered Element = 10 Contents of Element within Array is = K
Even Numbered Element = 12 Contents of Element within Array is = M
Even Numbered Element = 14 Contents of Element within Array is = O
Even Numbered Element = 16 Contents of Element within Array is = Q
Even Numbered Element = 18 Contents of Element within Array is = S
Even Numbered Element = 20 Contents of Element within Array is = U
Even Numbered Element = 22 Contents of Element within Array is = W
Even Numbered Element = 24 Contents of Element within Array is = Y
cout << "This is the title to your Program related to the alphabet." << endl
<< endl
<< "Select the number that coincides with the alphabet."<< endl
<< "For example, the number 7 should display the letter G." << endl
<< endl
<< "Enter a number between 1 and 26: ";
cin >> num;
cout << endl
<< "The number you selected: " << num << endl;
num--;
cout << "The letter related to this number: " << alphabet[num] << endl;
cout << endl
<< "PRINTING CONTENTS OF ARRAY and adding x to every other element" << endl
<< "==================================" << endl;
okay that you for your help. One more question, how can I show the index number of the array element. For example I have an array element char apples[3] = 'green';, i want to show it like like
Numbered Element = 3 Contents of Element within Array is = green
okay that you for your help. One more question, how can I show the index number of the array element. For example I have an array element char apples[3] = 'green';, i want to show it like like
Numbered Element = 3 Contents of Element within Array is = green
You're already doing something very similar in this line
cout << endl
<< "The number you selected: " << num << endl;
I want to extract the element number from the array with out using a separate counter:
I have and array of 3 apples
apples[3] = {'green','red','yellow'};
I have a for loop
for(i = 0; i <= 2; i++)
cout << "Element number is: " << /* I need the element number not the contents of the element */
<< "Contents of Element: " << apples[i];
Look at your own code. Do you know what you're writing, or is someone writing this code for you?
Code:
for(i = 0; i <= 2; i++)
cout << "Element number is: " << /* I need the element number not the contents of the element */
<< "Contents of Element: " << apples[i];
return 0;
Do you see what's in red? That is your "Element number". You used it to determine which element to output.
I want to extract the element number from the array with out using a separate counter
That may be "clear" to you, but it makes no sense to persons who have years of C++ experience.
You have an array, you accessed element "i" of the array, so "i" is the index you used to access the element.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; July 16th, 2010 at 11:11 AM.
I want to extract the element number from the array with out using a separate counter:
I have and array of 3 apples
apples[3] = {'green','red','yellow'};
I have a for loop
for(i = 0; i <= 2; i++)
cout << "Element number is: " << /* I need the element number not the contents of the element */
<< "Contents of Element: " << apples[i];
return 0;
I cant really get much clearer than that sir
So i is the element number. Just cout i wherever you want it. If i isn't the element number, you need to explain what you mean by that term.
Bookmarks