I am trying to do some homework and I am running into a problem. My homework is
•Using a for loop, print the contents of the array.
The output should appear like this:
PRINTING CONTENTS OF ARRAY
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
I have my code and it is working. However at the end of my alphabet a bunch of random characters and symbols appear. Is there anything you guys see that I am doing wrong?
Here is my code.
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
// main FUNCTION BEGIN PROGRAM EXECUTION
int main()
{
// ALPHABET ARRAY DECLARATIONS
char Letters [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'};
for (int i = 0; i < 27 ; i++)
{
cout<< "PRINTING CONTENTS OF ARRAY" << endl;
cout<< "===============================" << endl;
cout<< Letters << " ";
cout<< endl;
break;
}
return 0 ;
} // ***END main FUNCTION***
Basically the problem to put it simply is that it prints A-Z like I want it to but also prints a bunch of random symbols after Z. Any Ideas? As I am new to this I am sure it’s probably something simple.
Thanks in advance!
To remove the “bunch of random characters and symbols”, add a
NULto the end ofLetters:This is will print the alphabet 26 times, which may not be what you want. Edit: Previous statement wrong–I missed your
break;.