![]() |
.. (לתיקייה המכילה) | |
Q: Is the length of the "main" function limited to 16 lines? | |
A: Of course yes. "main" is a function as any other function. |
The program works for me, but the computer behaves in a different way than in your tests | |
First, make sure you choose the values in the order which has been defined in the assignment: for locating battleship the order is: x, y, dir_x, dir_y (left to right) And for attack the order is x, y. To check yourself, verify the following example: For seed = 5 the computer first chooses the location of the battleship of size 2: x=7 y=0 dir_x=-1 dir_y=-1 These values are bad selection and therefore the computer chooses again for this battleship. The chosen values are: x=6 y=9 dir_x=1 dir_y = -1 which are good selection. |
The input is separated by commas (,). How do I read it? | |
To read battleship location, use int res = scanf("%d,%d %d,%d", &x, &y, &dir_x, &dir_y); To read attack location, use int res = scanf("%d, %d", &x, &y); Recall that if res is different than the number of variables scanf attempts to read, then the input is incorrect (Tutorial 4). |
Can we assume that the correct input for the values seed, level? | |
You can't assume syntactic errors and the program should behave like every syntactic error. But you can assume that if there aren't syntactic errors, the input will be non-negative integers. Recall that checking for syntactic error should be done by checking the return value of scanf (Tutorial 4). |