Mar 21, 2013 at 4:43pm UTC
Can someone tell me why this won't work?
Some fresh code:)
This code should calculate a average value of a number of throws with a dice. I use random_device for this and it won't work.
#include <iostream>
#include <fstream>
#include <random>
using namespace std;
int main(int argc, char*argv[])
{
if(argc!=3)
{
cout<<"Wrong argument, dice type after "<<argv[0]<<endl;
return 1;
}
fstream input(argv[1]);
fstream input2(argv[2]);
if(atoi (argv[1]) < 1 )
{
cout<<"Must throw the dice at least one time!"<<endl;
return 2;
}
if((atoi argv[2]) < 1 || (atoi argv[2]) > 6)
{
cout<<"Wrong dice type"<<endl;
return 2;
}
int dice_type = atoi(argv[1]);
int throws = atoi(argv[2]);
double sum = 0;
random_device rnd;
for(int i=0; i<throws; ++i)
{
sum = sum + rnd() % dice_type +1;
}
cout<<"The average value of"<<throws<<" throws with a "<<dice_type<<" dice type is, "<<sum/throws;
return 0;
}
Last edited on Mar 21, 2013 at 4:45pm UTC
Mar 21, 2013 at 4:49pm UTC
if ((atoi argv[2]) < 1 || (atoi argv[2]) > 6)
Error is here.
Next time read compiler errors and try to fix it yourself
Mar 21, 2013 at 4:56pm UTC
It still says that random_device wasn't declared in this scope!
Mar 21, 2013 at 5:00pm UTC
check your brackets?
Last edited on Mar 21, 2013 at 5:00pm UTC
Mar 21, 2013 at 5:02pm UTC
They are correct what i can see
Mar 21, 2013 at 5:05pm UTC
atoi argv[2]
→ atoi(argv[2])
I do not believe that compiler didn't tell you about this error. If it really didn't complain abot this, throw it out. It's shit.
Mar 21, 2013 at 5:12pm UTC
It did complain but i have fixed it now. It still complains about random_device wasn't declared in this scope
Mar 21, 2013 at 5:20pm UTC
did your compiler supports random library?
because your code works for me