array help!

so heey guys again..
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
/*
6-60 Coding

A study of cryptography and its growth as a science can shed light on the nature of languages 
and on certain aspects of history. For example, the level of education of the Boers in the Boer War 
can be noted from the fact that the British officers often sent messages written in normal schoolboy Latin, 
secure in the fact that if they did fall into the wrong hands, they could not be understood. One of the 
simplest codes (used from the times of the Greeks) is representing the letters of the alphabet by numbers. 
An array contains a series of two-digit integers. Each integer represents one character of the alphabet as follows:

00 represents a blank space
01 represents an A
02 represents a B
03 represents a C
.
.
.
26 represents a Z

Write a program that reads the entries and prints the characters corresponding to the integers. 
The program should check that all integers are between 0 and 26. If this is not the case, the program should print a message 
indicating that the data is invalid. 
*/
#include <iostream>
using namespace std;
int main()
{
  int total, num;
  int alphabet [27] = {'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'};
  cout << "I will transcribe your numbers into letters.\n";
  cout << "How many numbers are you entering: \n";
  cin >> total;
   for ( int n = 0; n <= total; n++)
  {
   cout << "Enter your number: \n";
   cin >> num;
   if ( num < 0 || num > 26 )
   {cout << "the data is not valid.\n"; break;}
   else 
   {cout << num << " is " << alphabet[num] << endl; }
  }

   system ("pause");
}


this is my code and everything's spiffy except for the array part! when i insert a number like 05, it gives me a number like 102 and not e... and does anyone know how i would output all the letters at the end like in a word?
Yeah, the array needs to be an array of characters, not integers. Also, why does it have a length of 27?
so wait. isnt the stuff inside the array characters? abcdef... ? and i'm not sure... o.o should it be 26?
the a array must be a char type.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main()
{
  int total, num;
  char alphabet [27] = {' ','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'};
  cout << "I will transcribe your numbers into letters.\n";
  cout << "How many numbers are you entering: \n";
  cin >> total;
  cout << "Enter your number: \n";
   for ( int n = 0; n < total; n++)
  {
   
   cin >> num;
   if ( num < 0 || num > 26 )
   {cout << "the data is not valid.\n"; break;}
   else 
   {cout << num << " is " << alphabet[num] << endl; }
  }

   system ("pause");
}
Yeahh , Array should be of type character. You have declared integer character and

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main()
{
  int total, num;
  char alphabet [27] = {' ','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'};
  cout << "I will transcribe your numbers into letters.\n";
  cout << "How many numbers are you entering: \n";
  cin >> total;
  cout << "Enter your number: \n";
   for ( int n = 0; n < total; n++)
  {
   
   cin >> num;
   if ( num < 0 || num > 26 )
   {cout << "the data is not valid.\n"; break;}
   else 
   {cout << num << " is " << alphabet[num] << endl; }
  }

   system ("pause");
}


ohh question, why is there a space before the a? if i do char [26] , can i just put the 26 letters?
Yeah, sure you can. It's your array. :-)
Topic archived. No new replies allowed.