converting interger to character using pointers

Where i can put the pointer so that those intergers will be converted to character

This is the code:

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
#include <iostream>
#include <limits>
using namespace std;
bool encountered[9] = {}; 
int main(){
	int z[3][3];
	char a=0,b=1,c=2,d=3,e=4,f=5,g=6,h=7,i=8,j=9;
	for(int i = 0; i <3; i++)
{
    for (int j=0 ; j<3 ; ++j)
    {
        cout << "Num " << (j+1)+3*i << ": ";
        cin >> z[i][j];
        if(cin.fail()) 
        {
            std::cerr << "Invalid input" << std::endl;
            cin.clear();
            cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
            --j; 
            continue;
        }
        if(z[i][j] > 9 || z[i][j] < 0)
        {
            std::cerr << "Invalid number, should be between 0 and 9" << std::endl;
            --j;
        }
        else if(encountered [z[i][j]-1])
        {
            std::cerr << "You already entered that number" << std::endl;
            --j;
        }
        else 
        {
            encountered[z[i][j]-1] = true; 
        }
    }
}
	 for(char i = 0; i <3; i++)
    {
        for (char j=0 ; j<3 ; ++j)
        {
            cout << z[i][j] << " ";
        }
        cout << endl<<"\n";
    }
    cout<<"Its a magic square";
}
Last edited on
Last edited on
Topic archived. No new replies allowed.