Can you tell me if this is C++ (so I can go to the C++ forum) or code::blocks or Win7?
(I am using 12.11 on a win7 vaio)
Code A produces results A. the array should be all the same (1's). in mint 15 (home built desktop), it is all the same. In Win7 it is as below Changing the enum value written to the array causes the error to be slightly different, but still a small numerical error in a small part of the array.
The main thing is about using enums and arrays. I thought enums were just integers, where the programmer can use a word for readability. Writing an enum value into an array seems to produces consistent results that I am not expecting. Is this my use of C++, or a feature of CB?
COde A:
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
//declare enum
enum testone {
yes,
no,
maybe,
null
};
//declare variables
int test_one, test_two, test_three, test_four;
int array[2][2];
string string_one, string_two, string_three, string_four;
//display variables
cout << test_one << " : " << test_two << " : " << test_three <<" : " << test_four << "\n";
cout << "now strings" << string_one <<" : " << string_two << " : " << string_three <<" : " << string_four << "\n";
//fill strings - I am aware this is wrong - just an experiment in using enums
string_one = yes;
string_two = no;
string_three = maybe;
string_four = null;
//reprint string
cout << "now strings" << string_one <<" : " << string_two << " : " << string_three <<" : " << string_four << "\n";
//fill ints
test_one = yes;
test_two = no;
test_three = maybe;
test_four = null;
//print ints
cout << test_one << " : " << test_two << " : " << test_three <<" : " << test_four << "\n";
//print array
for(int i=0;i<3; i++)
{
for (int j=0;j<3; j++)
{
cout << array[i][j] << " : ";
}
cout <<"\n";
}
//fill array
for(int i=0;i<3; i++)
{
for (int j=0;j<3; j++)
{
array[i][j] =no;
}
cout <<"\n";
}
//reprint array
for(int i=0;i<3; i++)
{
for (int j=0;j<3; j++)
{
cout << array[i][j] << " : ";
}
cout <<"\n";
}
cout << "Hello world!" << endl;
return 0;
}
results A:
1 : -2342344 : -23423432 : -23423432
now strings : : :
now strings : : :
0 : 1 : 2 : 3
-23434 : 0 : 423434 :
23423 : 234234 : -34544543 :
2342342 : -234324 : 0 :
1 : 1 : 1 :
1 : 1 : 1 :
1 : 0 : 2 :
Hello World!
Process returned 0 (0x0) execution time : 0.004 s
Press ENTER to continue
many thanks