Question: using System; using static System.Runtime.InteropServices.JavaScript.JSType; class HungryRabbit { public static void Main ( string [ ] args ) { int [ , ] garden =
using System;
using static System.Runtime.InteropServices.JavaScript.JSType;
class HungryRabbit
public static void Mainstring args
int garden
;
int totalCarrots CalculateTotalCarrotsgarden;
Console.WriteLineTotal carrots eaten by the rabbit are: totalCarrots;
public static int CalculateTotalCarrotsint garden
int rows garden.GetLength;
int cols garden.GetLength;
int x int y FindStartingPositiongarden rows, cols;
int totalCarrots ;
while true
totalCarrots gardenx y;
gardenx y;
int nextX, int nextY GetNextPositiongarden x y;
if nextX && nextY
break;
x nextX;
y nextY;
return totalCarrots;
private static int int FindStartingPositionint garden, int rows, int cols
int centerRow rows ;
int centerCol cols ;
int possibleCenters
gardencenterRow centerCol
rows && cols gardencenterRow centerCol : int.MinValue,
cols gardencenterRow centerCol : int.MinValue,
rows && cols gardencenterRow centerCol : int.MinValue
;
int maxCarrots ;
int startX centerRow, startY centerCol;
for int i ; i possibleCenters.Length; i
if possibleCentersi maxCarrots
maxCarrots possibleCentersi;
if i startX centerRow ;
if i startY centerCol ;
if i
startX centerRow ;
startY centerCol ;
return startX startY;
private static int int GetNextPositionint garden, int x int y
int rows garden.GetLength;
int cols garden.GetLength;
int directions
Up
Down
Left
Right
;
int maxCarrots ;
int nextX nextY ;
foreach var dir in directions
int newX x dir;
int newY y dir;
if newX && newX rows && newY && newY cols && gardennewX newY maxCarrots
maxCarrots gardennewX newY;
nextX newX;
nextY newY;
return nextX nextY;
It is coming up with a CS error at:
int maxCarrots ;
int nextX nextY ;
foreach var dir in directions
int newX x dir;
int newY y dir;
if newX && newX rows && newY && newY cols && gardennewX newY maxCarrots
maxCarrots gardennewX newY;
nextX newX;
nextY newY;
return nextX nextY;
error is:
Severity Code Description Project File Line Suppression State
Error active CS Cannot apply indexing with to an expression of type 'int' HungryRabbit C:UsersanimesourcereposHungryRabbitHungryRabbitProgramcs
And that is for errors it comes back as for that entire area. Please help! Code is in C#
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
