Issue with array

I am writing an assignment for my class and I think I have everything pretty much done and setup but I am encountering an issue with the loop and stopping it at 26 or the last letter. The loop continues and writes the printout to 42 instead of stopping.

I can't figure out what the issue is here, I tried searching some other old threads with similar assignments, and I can't seem to find the difference between mine and the code they wrote?

I don't want to just copy code from an old thread as I wont learn that way, I want to know exactly what I am doing wrong in my code.



I will post the whole code first, than another code block with just the loop that I am having the issue with.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
 #include "stdafx.h"
#include<iostream>
#include<iomanip>

int _tmain(int argc, _TCHAR* argv[])   // Allows VS Express to run without header and error free
{
	return 0;
}

// Start Of Assignment

using std::cin;
using std::cout;
using std::endl;
using std::setw;

	int main()
		// Declaring The Arrays - Pointers
		// Printing Concepts
	{                                       
		char pletter2[26]=  { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
		char* pphrase = "PRINTING CONTENTS OF THE ARRAY";
		char* pphrase2 = "==============================";
		char* pphrase3 = "PRINTING CONTENTS OF THE ARRAY and adding x to every other element";
		char* pphrase4 = "==================================================================";
		char pphrase5 = 'x';
		char* pphrase6 = "PRINTING CONTENTS OF THE ARRAY USING MOD OPTION";
		char* pphrase7 = "===============================================";

		int number = 0;
		

		



		    cout<<endl;
			cout <<pphrase;
		    cout <<endl;
		    cout <<pphrase2;
			cout <<endl;

	     for(int i = 0; i < 26; i++) // Elements with counter
		{
			
		    
			 cout <<pletter2[i];
			
		
		}
          
			cout <<endl;
			cout <<endl;
		    cout <<"Review the alphabet above and enter the coinciding number of the letter: "<<endl; // Prompting for number entry
		    cout <<endl;
			cout <<"The Letter A is 0, Letter B is 1, Letter C is 2, and so on.."<<endl;  // Brief example
			cin >>number;

		 if ( number >=1 && number <=26)        // If the number 1-26 is entered the following engages
		 {
			     cout <<"Selected Number: "<<number<<endl;
		         cout <<"The letter that represents that number is: "<<pletter2[number-1]<<endl;
		 }
		          else 
		 {
			         cout<<"There has been a problem with your selection try again please!"<<endl;
		 }
		 
		 
		 
			
			 
		                                   
         cout <<endl;
         cout <<endl;
		 cout << pphrase3;
		 cout <<endl;
		 cout <<pphrase4;
		 cout <<endl;

			for(int i = 1; i < 2; i = i +2)    // Replacing X with every other letter after A
            {
              
			    pletter2[i] = pphrase5;
				
                  
				 for(int j = 0; j<26; j = j+2) 

					 cout <<pletter2[j]<<pletter2[i];
			         cout <<endl;
			}

		  cout <<endl;
	      cout <<endl;
		  cout <<endl; 
		  cout <<pphrase6;
		  cout <<endl;
		  cout <<pphrase7;


		  
		  int i;
		  
		  
 for(int i=0; pletter2[i] !='\0' ; i++)   
                
		  {
			   
			    
			   if ((pletter2[i] & 1) == 0)            // Detecting if selection is EVEN
              i=i+1;
           


		     cout <<endl;
			 cout <<"Even Numbered Element "<<i<<"    Contents of Element within Array is  "<<pletter2[i];
		     cout <<endl;
		  }
		  
		 {
              

		}

			return 0; // returns
		} // End of application
	
		 




This is the area of the problem, it continues to 44 instead of ending at 26...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
		  
 for(int i=0; pletter2[i] !='\0' ; i++)   
                
		  {
			   
			    
			   if ((pletter2[i] & 1) == 0)            // Detecting if selection is EVEN
              i=i+1;
           


		     cout <<endl;
			 cout <<"Even Numbered Element "<<i<<"    Contents of Element within Array is  "<<pletter2[i];
		     cout <<endl;
		  }
		  
		 {
I figured it out, instead of using this string

 
for(int i=0; pletter2[i] !='\0' ; i++)   


I went with the following
 
for (int i = 0; i < 26; ++i)


This way it ensures 26 is the end.
Topic archived. No new replies allowed.