Do you know what a debugger is?
Now is the time to find out what debugging options are available on your system. If you're using visual studio, it's all point and click.
> and possibly a diving by zero error at the end of the program.
You don't need to guess, you can find this out for yourself.
Your first skill to master being setting breakpoints and printing variables. You can learn a lot from your program simply by stopping and having a look to see if what the machine has done matches your expectation.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
$ gdb -q ./a.out
Reading symbols from ./a.out...done.
(gdb) b 28
Breakpoint 1 at 0x4009b3: file baz.cpp, line 28.
(gdb) run
Starting program: ./a.out
Breakpoint 1, main () at baz.cpp:28
28 cout << tries / hits;
(gdb) p tries
$1 = 10000
(gdb) p hits
$2 = 0
|
So yes, you have zero hits.
> yhigh = ylow + sin(angle);
First of all, sin() takes radians as the parameter, not degrees. So half your sin() results will be negative to begin with.
Second, given that ylow is either 0 or 1, there is only one specific value (PI/2) where sin() would return anything close to being actually 1 in order for your >= 2 test to succeed.