26x26 Grid

Pages: 12
I'm not quite understanding what's needed here. Do you ask the user for a letter? But then, each row has all the letters of the alphabet? If you mean the user enters two numbers, and you show the letter that intersects that, then the problem is each side is different. No intersections. So, please explain how this is to work, and we can work on it together.
Lets say that I enter, "I love pie".
It will read the "I" as the first letter, meaning it will look through row 1 to find letter I.
When it finds letter I, it will find the column number that, "I" in row 1 is under.
I in row 1 is column number 9.
In a sense, the coordinates are (1,9)
Now, since I'm assuming that coping the grid and rotating the duplicate grid twice, either to the left or the right, it will find the letter that corresponds with (1,9) of the duplicate grid.
The grid has 4 corners. Imagine each corner is labeled as either A, B, C or D.
A B = original letters D C = encrypted letters
C D & rotate the duplicate grid twice. B A

In short, "I love pie" will become "E dedc bum".
The "e" in love becomes a "c" while the "e" in pie become an "m".
Sorry, for any confusing.
@TruYadoo
Ah, I understand now. And a space, stays a space. If you need a little help, let me know. It sounds like a fun program.
I would definitely appreciate any further help except it doesn't kinda feel like I'm cheating myself.
If you know of any functions that I should use, I'm all ears. Or eyes..
Maybe with an explanation of what the function is for and how to use it, that'd be perfect.
Also, if you have any suggestions or tips, I'll be glad to read whatever you have to type.

I was also thinking that I should use a text file for "inputting" the desired message(s).
So that way, I could just open up my designated text file and type in whatever that I want to get encrypted and then have the program open the file, read it and encrypt everything until the eof.

See, I know what I want to do. I just don't know how to code it. =P
@TruYadoo
Here is a way to take a sentence and encrypt it. I did not put it in a function, but I will do that later, or wait and see what you come up with. Just copy and paste this just before
cout << endl << endl << "\t\t\t\t\t"; // Just adding tabs to center the "Press any key.. " text
The text you mentioned for checking, "I LOVE PIE", encrypts as noted..

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
char Text[80];
cout << endl << endl << "\t\t\t\t: Please enter a sentence to encrypt : " << endl;
cin.getline(Text, 80);
len=0; // For actual length of input
int next = 0; // For next line in array if what is being checked, IS a letter of the alphabet
for(x=0;x<80;x++)
       if (Text[x]!='\0')
	{
		len++;
		Text[x]=toupper(Text[x]); // Convert input to upper case since array is all upper
	}
	else
		break; // if end of inputted text, quit searching

for(x=0;x<len;x++)
{
	for(y=0;y<26;y++)
	{
		if(Text[x]== Letters[next][y])
		{
			cout << Letters[25-next][25-y]; // cout letter start from bottom-right
			// Text = "I LOVE PIE" : I located in row 0, column 9.
			// Letters[25-row] = 25, [25-column] = 18 which is an 'E'
		}
	}
	if(Text[x]>='A' && Text[x]<='Z')
		next++; // if alphabet , add 1 to variable next
	if(Text[x]<'A' || Text[x]>'Z')
		cout << Text[x];// if anything but the alpabet, just print it
}
Alright, sweet! Thank you very much.
I am using a different way to exit the program. With string goodbye; right below int main ()
1
2
3
4
5
6
7
8
9
10
do {
    cout << "\nType EXIT if you're ready to leave. ";
    cin >> goodbye;

    if (goodbye == "EXIT" || goodbye == "Exit" || goodbye == "exit")
      cout << "Goodbye!" << endl;

    else
      cout << "Invalid Input. Please try again. " << endl;
    } while (goodbye != "Exit" && goodbye != "EXIT" && goodbye != "exit");


I also added a string in between the encryption and the exit code.
1
2
3
4
5
6
7
8
9
 {
	  cout << "\n\nWould you like to encrypt something? Yes/No ";
	  cin >> encrypt;
	   
	  if (encrypt == "Yes" || encrypt == "YES" || encrypt == "yes")
	 	  goto loop;
	  
	  else (encrypt == "No" || encrypt == "NO" || encrypt == "no");
     }

If the user inputs yes, it loops back to the encryption but it just reads the question and then skips to asking "Would you like to encrypt something? again
@TruYadoo
You shouldn't really be using a goto command in your program. Just a do/while loop should be fine. After the grid is printed, the rest can be inside the do/while. You could just add 'Type Exit to quit' with the sentence asking for the sentence. The program already converts what is typed to uppercase, so there is no need to have all the variations of the word "Exit". So, it would be something like
1
2
3
4
5
6
do
{
cout << endl << endl << "\t\t\t\tType 'EXIT' to quit or\n\t\t\t\t: Please enter a sentence to encrypt : " << endl;
// Now all the program from above
// ......
} while(Text[0] != 'E' && Text[1] != 'X' && Text[2] != 'I' && Text[3] != 'T'); // since it's not a string, but chars 


I made these changes to what I'm dong in the program, and it works great. The word 'EXIT' gets converted and shown also.
doesn't work.
Error C2882, 'Text' illegal use of namespace identifier in expression
Change the variable of 'Text[]' to 'Grid[]' or whatever char name you used to get the input to the sentence to be encrypted
The char Text[80] ?
I just copied what you put.
Did you declare char Text[80]; in your declarations after main() ? If yes, please post your code here so I can see what might be wrong, or email it to me. My email is located in my User Profile. On the left side of that page is a menu that says, 'Send private message' under 'User: whitenite1'.

With this
1
2
3
4
5
6
do
{
cout << endl << endl << "\t\t\t\tType 'EXIT' to quit or\n\t\t\t\t: Please enter a sentence to encrypt : " << endl;
// Now all the program from above
// ......
} while(Text[0] != 'E' && Text[1] != 'X' && Text[2] != 'I' && Text[3] != 'T'); // since it's not a string, but chars  

I meant the program above that I sent, not the code you showed in your post.
@TruYadoo

While typing in a few sentences, I went over 26 letters, and got strange results, since the variable 'next' was accessing outside the array of Letters. To fix it, change
1
2
if(Text[x]>='A' && Text[x]<='Z')
   next++; // if alphabet , add 1 to variable next 
to
1
2
3
4
5
6
if(Text[x]>='A' && Text[x]<='Z')
{
  next++;; // if alphabet , add 1 to variable next 
   if (next>25) // Because Letter[][] array goes from 0 to 25
	next=0;
}
Last edited on
I have char Text[80]; declared just before cout << "\n\nPlease enter a sentence to encrypt: Or type EXIT to quit. ";
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
// Algorithm.cpp : main project file.
#include "StdAfx.h"
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;
using namespace System;

int main()
{
	int len;
	string encrypt;
	string exit;
	string goodbye;
	int width = 115, height = 35, row,xamount=1;
	Console::SetWindowSize(width, height );
	char Letters[26][26], temp;
	int x, y, z;
	for(y=0;y<26;y++) // 
	{
		for(x=0;x<26;x++)
		{
			Letters[y][x] = 'A'+x;
		}
	}
	cout << endl << endl;
	cout << "      ";
	for (y=0;y<26;y++)
	{
		cout << y+1 << "  ";
		if(y<9)
			cout << " ";
	}
	cout << endl;
 row = 1;
	do
	{
		for(x=0;x<xamount;x++)
		{
		temp = Letters[row][0];
		for(z=0;z<26;z++)
		{
			Letters[row][z] = Letters[row][z+1];
		}
		Letters[row][25] = temp;
		}
		row++;
		xamount=(row)+xamount;
	} while(row<26);

	for (y=0;y<26;y++)
	{
		if (y<9)
			cout << " ";
		cout << "  " << y+1 << " ";
		
		for(x=0;x<26;x++)
		{
			cout << "[" << Letters[y][x] << "] ";
		}
		if (y>16)
			cout << " ";
		cout << 26-y << endl;
	}
	cout << "      ";
	for (y=26;y>0;y--)
	{
		cout << y << "  ";
		if(y<=9)
			cout << " ";
	}
	do {
	char Text[80];
      cout << "\n\nPlease enter a sentence to encrypt: Or type EXIT to quit. ";
      cin.getline(Text, 80);
      len=0; // For actual length of input
      int next = 0; // For next line in array if what is being checked, IS a letter of the alphabet
      
	 for(x=0;x<80;x++)
       if (Text[x]!='\0')
	{
		len++;
		Text[x]=toupper(Text[x]); // Convert input to upper case since array is all upper
	}
	else
		break; // if end of inputted text, quit searching

for(x=0;x<len;x++)
 {
	for(y=0;y<26;y++)
	{
		if(Text[x]== Letters[next][y])
		{
			cout << Letters[25-next][25-y]; // cout letter start from bottom-right
			// Text = "I LOVE PIE" : I located in row 0, column 9.
			// Letters[25-row] = 25, [25-column] = 18 which is an 'E'
		}
	}
	if(Text[x]>='A' && Text[x]<='Z')
{
  next++;; // if alphabet , add 1 to variable next 
   if (next>25) // Because Letter[][] array goes from 0 to 25
	next=0;
}
	if(Text[x]<'A' || Text[x]>'Z')
		cout << Text[x];// if anything but the alpabet, just print it
 } 
  } while(Text[0] != 'E' && Text[1] != 'X' && Text[2] != 'I' && Text[3] != 'T');
	
	do {
    cout << "\nType EXIT if you're ready to leave. ";
    cin >> goodbye;

    if (goodbye == "EXIT" || goodbye == "Exit" || goodbye == "exit")
      cout << "Goodbye!" << endl;

    else
      cout << "Invalid Input. Please try again. " << endl;
    } while (goodbye != "Exit" && goodbye != "EXIT" && goodbye != "exit");

    Sleep(2000);

	return 0;
}
I'm also having an issue trying to create a Form Application project on Visual C++ 2010 Express.
Whenever I try to add a button, label, progress bar, etc; I get some error about my .NETframework version=v4.0.
I have Framework 4 Client Profile, Framework 4 Extended and Framework 4 Multi-Targeting Pack but nothing
@TruYadoo
Sorry about the Visual C++ 2010 Express problems. I only create console programs with 2008 Express. Anyway, Here is the corrected code. Your do loop wasn't necessary. The EXITing part is taken care of in the do/while (Text[0]!='E' ,etc.) The char Text[80];, belongs with the variable declarations after main(), not in with the do/loop. Otherwise, your trying to re-declare a variable, and that doesn't work. Also added for you, a way for the text to get printed at the bottom of the screen at the same locations, so the screen doesn't scroll. Thanks for letting me help with your program. It's been fun..
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Algorithm.cpp : main project file.
#include "stdafx.h" // Using MS Visual C++ 2008 Express - Remove if not needed
#include <iostream>
#include <string>
#include <conio.h>
#include <windows.h>

using namespace std;
using namespace System;

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;

void WaitKey();
void gotoXY(int x, int y);
void gotoXY(int x, int y, string text);

int main()
{
	int width = 115, height = 38, row, xamount=1, len;
	Console::SetWindowSize(width, height );
	char Letters[26][26], temp;
	char Text[80];
	string erase(80,' ');
	int x, y, z;
	for(y=0;y<26;y++)  
	{
		for(x=0;x<26;x++)
		{
			Letters[y][x] = 'A'+x;
		}
	}
	cout << endl << endl;
	cout << "      ";
	for (y=0;y<26;y++)
	{
		cout << y+1 << "  ";
		if(y<9)
			cout << " ";
	}
	cout << endl;
 row = 1;
	do
	{
		for(x=0;x<xamount;x++)
		{
		temp = Letters[row][0];
		for(z=0;z<26;z++)
		{
			Letters[row][z] = Letters[row][z+1];
		}
		Letters[row][25] = temp;
		}
		row++;
		xamount=(row)+xamount;
	} while(row<26);

	for (y=0;y<26;y++)
	{
		if (y<9)
			cout << " ";
		cout << "  " << y+1 << " ";
		
		for(x=0;x<26;x++)
		{
			cout << "[" << Letters[y][x] << "] ";
		}
		if (y>16)
			cout << " ";
		cout << 26-y << endl;
	}
	cout << "      ";
	for (y=26;y>0;y--)
	{
		cout << y << "  ";
		if(y<=9)
			cout << " ";
	}
	do
	{
	gotoXY(46,30,"Type 'Exit' to quit or");
	gotoXY(38,31,": Please enter a sentence to encrypt :");
	gotoXY(5,33);
	cin.getline(Text, 80);
	len=0;
	int next = 0;
	for(x=0;x<80;x++)
		if (Text[x]!='\0')
		{
			len++;
			Text[x]=toupper(Text[x]);
		}
		else
			break;
	gotoXY(5,33,erase);
	gotoXY((115-len)/2,33,Text);
	gotoXY((115-len)/2,34);
	for(x=0;x<len;x++)
	{
		for(y=0;y<26;y++)
		{
			if(Text[x]== Letters[next][y])
			{
				cout << Letters[25-next][25-y];
			}
		}
		if(Text[x]>='A' && Text[x]<='Z')
		{
			next++;
			if (next>25)
				next=0;
		}
		if(Text[x]<'A' || Text[x]>'Z')
			cout << Text[x];
	}
	WaitKey();
	for(x=33;x<37;x++)
		gotoXY(5,x,erase);
	} while(Text[0] != 'E' && Text[1] != 'X' && Text[2] != 'I' && Text[3] != 'T');

	gotoXY(44,36);
	return 0;
}

void WaitKey()
{
	gotoXY(43,36,"Press any key to continue...");
	while (_kbhit()) _getch(); // Empty the input buffer
	_getch(); // Wait for a key
	while (_kbhit()) _getch(); // Empty the input buffer (some keys sends two messages)
}

void gotoXY(int x, int y) 
{ 
CursorPosition.X = x; 
CursorPosition.Y = y; 
SetConsoleCursorPosition(console,CursorPosition); 
}

void gotoXY(int x, int y, string text) 
{ 
CursorPosition.X = x; 
CursorPosition.Y = y; 
SetConsoleCursorPosition(console,CursorPosition);
cout << text;
}
Topic archived. No new replies allowed.
Pages: 12