Do you think it's lazy of me If I write code, to write my code?

So an example of my lazyness would be whats below this
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
#include <iostream>
#include <string>

int main()
{
int letter(0);
std::cout << "Please type in a number and a letter will be printed on" << endl << "screen corresponding to it's value in the English Alphabet" << std::endl << std::endl;
std::string ss ("The letter that corosponds to that value is ");
Mistake:
std::cin >> letter;
std::cout << std::endl;
if(letter == 1){std::cout << ss << 'a';}
if(letter == 2){std::cout << ss << 'b';}
if(letter == 3){std::cout << ss << 'c';}
if(letter == 4){std::cout << ss << 'd';}
if(letter == 5){std::cout << ss << 'e';}
if(letter == 6){std::cout << ss << 'f';}
if(letter == 7){std::cout << ss << 'g';}
if(letter == 8){std::cout << ss << 'h';}
if(letter == 9){std::cout << ss << 'i';}
if(letter == 10){std::cout << ss << 'j';}
if(letter == 11){std::cout << ss << 'k';}
if(letter == 12){std::cout << ss << 'l';}
if(letter == 13){std::cout << ss << 'm';}
if(letter == 14){std::cout << ss << 'n';}
if(letter == 15){std::cout << ss << 'o';}
if(letter == 16){std::cout << ss << 'p';}
if(letter == 17){std::cout << ss << 'q';}
if(letter == 18){std::cout << ss << 'r';}
if(letter == 19){std::cout << ss << 's';}
if(letter == 20){std::cout << ss << 't';}
if(letter == 21){std::cout << ss << 'u';}
if(letter == 22){std::cout << ss << 'v';}
if(letter == 23){std::cout << ss << 'w';}
if(letter == 24){std::cout << ss << 's';}
if(letter == 25){std::cout << ss << 'y';}
if(letter == 26){std::cout << ss << 'z';}
if(letter > 26){std::cout <<  "I'm sorry, but I think the English Alphabet only has 26 letters.\nTry again -- but lets see if you're a bit smarter." << std::endl;goto Mistake;}
*/
//Add comebacks to LetterFinder when done 

And below this is the beast that mainly created the thing from above:
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
//Automated scripting assistant

int a(0),b(0);
std::string letterletter;
cout << "std::cout << "Please type in a number and a letter will be printed on" << endl << "screen corresponding to it's value in the English Alphabet" << std::endl << std::endl;" << endl <<
"std::string ss ("The letter that corosponds to that value is ");" << endl <<
"Mistake:" << endl;
std::cin >> letter;
std::cout << std::endl;
while (a <= 26){
++a;++b;
if(a == 1){letterletter='a';}
if(a == 2){letterletter='b';}
if(a == 3){letterletter='c';}
if(a == 4){letterletter='d';}
if(a == 5){letterletter='e';}
if(a == 6){letterletter='f';}
if(a == 7){letterletter='g';}
if(a == 8){letterletter='h';}
if(a == 9){letterletter='i';}
if(a == 10){letterletter='j';}
if(a == 11){letterletter='k';}
if(a == 12){letterletter='l';}
if(a == 13){letterletter='m';}
if(a == 14){letterletter='n';}
if(a == 15){letterletter='o';}
if(a == 16){letterletter='p';}
if(a == 17){letterletter='q';}
if(a == 18){letterletter='r';}
if(a == 19){letterletter='s';}
if(a == 20){letterletter='t';}
if(a == 21){letterletter='u';}
if(a == 22){letterletter='v';}
if(a == 23){letterletter='w';}
if(a == 24){letterletter='s';}
if(a == 25){letterletter='y';}
if(a == 26){letterletter='z';}
std::cout << "if(letter == " << b << "){std::cout << ss << '"<< letterletter <<";}"<<std::endl;}
    return 0;
} 

So really, is this good programmer ethics?
Last edited on
If you have a repetitive task it is good to think about more efficient ways to do it. writing code is no exception.

But you were not very lazy. A character can be represented as an integer and an integer can be represented as a character...
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

int main()
{
	int base = static_cast<int>('a')-1;
	for (int a=1; a<=26; a++)
	{
		std::cout << "if(letter == " << a << "){std::cout << ss << '["<< static_cast<char>(a+base) <<"]';}"<<std::endl;
	}
	system("pause");
	return 0;
}
Last edited on
Update to the automated scripter:
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
//Automated scripting assistant

int a(0),b(0);
std::string letterletter;
std::string MistakeMessage1("I'm sorry, but I think the English Alphabet only has 26 letters.");
std::string MistakeMessage2("Try again -- but this time lets see if you're a bit smarter");
std::cout << "int letter=0" << std::endl << "std::cout << Please type in a number and a letter will be printed on screen corresponding to it's value in the English Alphabet << " << "std::endl << std::endl;" 
<< std::endl <<
"std::string ss (The letter that corosponds to that value is );" << std::endl <<
"std::string CC1 (');" << std::endl <<
"std::string CC2 (');"<< std::endl << "Mistake:" << std::endl;
std::string CC1 ("'");
std::string CC2 ("'");
while (a <= 26){
++a;++b;
if(a == 1){letterletter='a';}
if(a == 2){letterletter='b';}
if(a == 3){letterletter='c';}
if(a == 4){letterletter='d';}
if(a == 5){letterletter='e';}
if(a == 6){letterletter='f';}
if(a == 7){letterletter='g';}
if(a == 8){letterletter='h';}
if(a == 9){letterletter='i';}
if(a == 10){letterletter='j';}
if(a == 11){letterletter='k';}
if(a == 12){letterletter='l';}
if(a == 13){letterletter='m';}
if(a == 14){letterletter='n';}
if(a == 15){letterletter='o';}
if(a == 16){letterletter='p';}
if(a == 17){letterletter='q';}
if(a == 18){letterletter='r';}
if(a == 19){letterletter='s';}
if(a == 20){letterletter='t';}
if(a == 21){letterletter='u';}
if(a == 22){letterletter='v';}
if(a == 23){letterletter='w';}
if(a == 24){letterletter='s';}
if(a == 25){letterletter='y';}
if(a == 26){letterletter='z';}
std::cout << "if(letter == " << b << "){std::cout << ss << CC1 << '"<< letterletter <<"' << CC2;}"<<std::endl;}
std::cout << "if(letter > 26){std::cout <<  " << CC1 << MistakeMessage1 << CC2 << " << std::endl << " << CC1 << MistakeMessage2 << CC2 << " << std::endl;goto Mistake;}";
Last edited on
@Nico

If you have a repetitive task it is good to think about more efficient ways to do it. writing code is no exception.

But you were not very lazy. A character can be represented as an integer and an integer can be represented as a character...

Well thanks for telling me, I was having some doubts
Last edited on
Topic archived. No new replies allowed.