I am working only with integers and want to create a new instance of Fraction. I receive the error that I “Cannot implicitly convert type. ‘Fractions.Fraction’ to ‘int'”. The problem has to do with creating the new instance in this specific method. I need to return all three values from the method back to the class.
I have stepped through the code with the debugger and verified that the values are getting changed correctly. I am just unable to get them to return correctly. The error is on the last line of the reduce method. Still somewhat new to C# and would appreciate any suggestions.
public static int Reduce(int wholeNum, int numer, int denomi)
{
int reduceWhole = (int)wholeNum;
while(numer > denomi)
{
numer -= denomi;
reduceWhole += 1;
}
while (denomi % numer == 0)
{
int factor = (int)denomi/numer;
numer = 1;
denomi = factor;
}
return new Fraction(reduceWhole, numer, denomi);
}
Then simply change the signature of the method to return
Fractioninstead ofint: