C++ Class identifiers

Hello everyone,I am kinda begginer in c++ and I would like to ask one question in the program code I wrote.It is supposed to have one default konstruktor,one overloaded and one to generate randomly.When I start it works for the first part of random generating and output on screen and the default wich would be number of dices 3 and 5 is also written on screen but it doesnt work for the last one where I should be able to put 2 random numbers as if roll was thrown.It says that variables x and y arent defined but I think i did define them in that part Dice (int x, int y)
{
a=x;
b=y;
}
and if I add x and y variables to private part it will ignore it and throw its own number despite what I wrote for numbers when it asks.
Thanks

#include <iostream>
#include <time.h>
using namespace std;
class Dice
{
private:
int a,b;
public:
Dice ()
{
a=3;
b=5;
}
Dice (int x, int y)
{
a=x;
b=y;
}
void Cheating()
{
cout<<"Type in number for dice number 1;"<<endl;
cin>>x;
cout<<"Type in number for dice number 2;"<<endl;
cin>>y;
}
void Throw()
{
cout<<"Throwing dice number 1..."<<endl;
srand ((unsigned int)time(NULL));
a=rand() %6+1;
cout<<"Throwing dice number 2..."<<endl;
srand ((unsigned int)time(NULL));
b=rand() %6+1;
}
void GetDice()
{
if (a==6 && b==6)
{
cout<<"Both dices got number 6 ,throwing dices again."<<endl;
cout<<"Throwing again..."<<endl;
cout<<"Throwing dice number 1..."<<endl;
srand ((unsigned int)time(NULL));
a=rand() %6+1;
cout<<"Throwing dice number 2..."<<endl;
srand ((unsigned int)time(NULL));
b=rand() %6+1;
}
else
{
cout<<"First dice got number:"<<a<<" and second dice got number:"<<b<<endl;
}
}
};
int main()
{
Dice i;
Dice j;
Dice k;
i.Throw();
i.GetDice();
j.GetDice();
k.Cheating();
k.GetDice();
system("PAUSE");
return 0;
}
constructor for 1 and 2

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <time.h>
using namespace std;
class Dice
{
private:
int a,b;
public:
Dice ()
{
a=3;
b=5;
}
Dice (int x, int y)
{
a=x;
b=y;
}
void Cheating()
{
cout<<"Type in number for dice number 1;"<<endl;
cin>>x;
cout<<"Type in number for dice number 2;"<<endl;
cin>>y;
}
void Throw()
{
cout<<"Throwing dice number 1..."<<endl;
srand ((unsigned int)time(NULL));
a=rand() %6+1;
cout<<"Throwing dice number 2..."<<endl;
srand ((unsigned int)time(NULL));
b=rand() %6+1;
}
void GetDice()
{
if (a==6 && b==6)
{
cout<<"Both dices got number 6 ,throwing dices again."<<endl;
cout<<"Throwing again..."<<endl;
cout<<"Throwing dice number 1..."<<endl;
srand ((unsigned int)time(NULL));
a=rand() %6+1;
cout<<"Throwing dice number 2..."<<endl;
srand ((unsigned int)time(NULL));
b=rand() %6+1;
}
else
{
cout<<"First dice got number:"<<a<<" and second dice got number:"<<b<<endl;
}
}
};
int main()
{
Dice i;
Dice j;
Dice k;
i.Throw();
i.GetDice();
j.GetDice();
k.Cheating();
k.GetDice();
system("PAUSE");
return 0;
} 
Fixed 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <time.h>
using namespace std;
class Dice
{
private:
int a,b;
public:
Dice ()
{
a=3;
b=5;
}
Dice (int x, int y)
{
a=x;
b=y;
}
void Cheating()
{
	int x;
	int y;
cout<<"Type in number for dice number 1;"<cin>>x;
cout<<"Type in number for dice number 2;"<<endl;
cin>>y;
}
void Throw()
{
cout<<"Throwing dice number 1..."<<endl;
srand ((unsigned int)time(NULL));
a=rand() %6+1;
cout<<"Throwing dice number 2..."<<endl;
srand ((unsigned int)time(NULL));
b=rand() %6+1;
}
void GetDice()
{
if (a==6 && b==6)
{
cout<<"Both dices got number 6 ,throwing dices again."<<endl;
cout<<"Throwing again..."<<endl;
cout<<"Throwing dice number 1..."<<endl;
srand ((unsigned int)time(NULL));
a=rand() %6+1;
cout<<"Throwing dice number 2..."<<endl;
srand ((unsigned int)time(NULL));
b=rand() %6+1;
}
else
{
cout<<"First dice got number:"<<a<<" and second dice got number:"<<b<<endl;
}
}
};
int main()
{
Dice i;
Dice j;
Dice k;
i.Throw();
i.GetDice();
j.GetDice();
k.Cheating();
k.GetDice();
system("PAUSE");
return 0;
}  


Hope intent is still there.
I didin't really get it...what should I change or where is mistake to make it work consutrctor one has already default parametres for a and b and constructor 2 should be taking my own parametres when I write them as variables x and y and equal them with a and b and output it on the screen but it says x and y arent defined
Well you just added int x,y; in the Cheating function now it can bypass the error that x and y arent defined but still it doesnt change the outcome.
k.Cheating();-when it starts i write number 3 and 4 for example
k.GetDice();-here it should take 3 and 4 as a and b but it ignores it and rolls dice again giving some else results instead
Topic archived. No new replies allowed.