Review a solution for the output math operations as specific number types challenge

Completed

The following code is one possible solution for the challenge from the previous unit.

int value1 = 11;
decimal value2 = 6.2m;
float value3 = 4.3f;

// The Convert class is best for converting the fractional decimal numbers into whole integer numbers
// Convert.ToInt32() rounds up the way you would expect.
int result1 = Convert.ToInt32(value1 / value2);
Console.WriteLine($"Divide value1 by value2, display the result as an int: {result1}");

decimal result2 = value2 / (decimal)value3;
Console.WriteLine($"Divide value2 by value3, display the result as a decimal: {result2}");

float result3 = value3 / value1;
Console.WriteLine($"Divide value3 by value1, display the result as a float: {result3}");

This code is merely "one possible solution" because there's likely several ways to solve this challenge. The solution uses much casting (and a call to convert); however, it's possible another approach works equally well. Just make sure your result matches the following output.

Divide value1 by value2, display the result as an int: 2
Divide value2 by value3, display the result as a decimal: 1.4418604651162790697674418605
Divide value3 by value1, display the result as a float: 0.3909091

If you were successful, congratulations! Continue on to the knowledge check in the next unit.

Important

If you had trouble completing this challenge, maybe you should review the previous units before you continue on.