I wrote a program about getting a die number. But this die will give number 1, 2, 4 , 5 , 7, 8. Therefore, i used if control statement to get these numbers. However, I got number 8 only. I don't what problem is. Could you help me to solve the problem?
#include <iostream>
#include <iomanip>
#include <cstdlib>
usingnamespace std;
int main()
{
int die;
die = (1 + rand() % 6);
if (die == 3)
{
die = 4;
}
if (die ==4)
{
die = 5;
}
if (die == 5)
{
die = 7;
}
if (die == 6)
{
die = 8;
}
for (int i = 1; i <= 10; i++)
{
cout << die << endl;
}
return 0;
}
After posting this question, I may find out the solution. But it produced some number only, not entire numbers in this range are produced. For example, it gave number 1,7,8 randomly. Is it a problem?
#include <iostream>
#include <iomanip>
#include <cstdlib>
usingnamespace std;
int main()
{
int die;
for (int i = 1; i <= 10; i++)
{
die = (1 + rand() % 6);
if (die == 3)
{
die = 4;
}
if (die == 4)
{
die = 5;
}
if (die == 5)
{
die = 7;
}
if (die == 6)
{
die = 8;
}
cout << die << endl;
}
return 0;
}