Help fast!

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
if((atoi argv[2]) < 1 || (atoi argv[2]) > 6)
Error is here.
Next time read compiler errors and try to fix it yourself
It still says that random_device wasn't declared in this scope!
check your brackets?
Last edited on
They are correct what i can see
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.
It did complain but i have fixed it now. It still complains about random_device wasn't declared in this scope
did your compiler supports random library?
because your code works for me
Topic archived. No new replies allowed.