S
Shock
Hi everybody,
I have posted here before and got great help, so thanks in advance. I
am working myself through deitel how to program c++ 4th edition and I
am having a small problem with some code. Below is my code and the
error message I am receiving. I am pretty sure the error is somewhere
in the morsecode array, but not sure where. I am very frustrated.
Any help is appreciated.
// Exercise 5.47 - Chapter 5
// Author: Corey Perkins
// Description: Convert plaintext to morsecode
#include <iostream>
#include <cctype>
using std::cin;
using std::cout;
using std::endl;
int main()
{
char morsecode[36] = {"-----", // 0
".----", // 1
"..---", // 2
"...--", // 3
"....-", // 4
".....", // 5
"-....", // 6
"--...", // 7
"---..", // 8
"----.", // 9
".-", // 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 alphabet[36] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'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 plaintext[80];
int where;
while ( cin.getline (plaintext, 80, '\n'))
{
for ( int i = 0; i < strlen( plaintext ); i++ )
{
char c = toupper(plaintext (i));
if ( isupper (c) )
{
where = c - 'A' + 10;
cout << morsecode[ where ] << " ";
}
else if ( isdigit (c) )
{
where = c - '0';
cout << morsecode[ where ] << " ";
}
else if ( isspace (c) )
{
cout << ' ';
}
}
cout << "\nNext:";
}
cout << endl;
return 0;
}
I have posted here before and got great help, so thanks in advance. I
am working myself through deitel how to program c++ 4th edition and I
am having a small problem with some code. Below is my code and the
error message I am receiving. I am pretty sure the error is somewhere
in the morsecode array, but not sure where. I am very frustrated.
Any help is appreciated.
// Exercise 5.47 - Chapter 5
// Author: Corey Perkins
// Description: Convert plaintext to morsecode
#include <iostream>
#include <cctype>
using std::cin;
using std::cout;
using std::endl;
int main()
{
char morsecode[36] = {"-----", // 0
".----", // 1
"..---", // 2
"...--", // 3
"....-", // 4
".....", // 5
"-....", // 6
"--...", // 7
"---..", // 8
"----.", // 9
".-", // 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 alphabet[36] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'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 plaintext[80];
int where;
while ( cin.getline (plaintext, 80, '\n'))
{
for ( int i = 0; i < strlen( plaintext ); i++ )
{
char c = toupper(plaintext (i));
if ( isupper (c) )
{
where = c - 'A' + 10;
cout << morsecode[ where ] << " ";
}
else if ( isdigit (c) )
{
where = c - '0';
cout << morsecode[ where ] << " ";
}
else if ( isspace (c) )
{
cout << ' ';
}
}
cout << "\nNext:";
}
cout << endl;
return 0;
}