0

this is the code of my program:

       `Console.WriteLine("This is a division app");
        Console.Write("Please input a whole number(maximum is 2,147,483,647): ");
        int number1 = Convert.ToInt32 (Console.ReadLine());
        Console.Write("Please input another whole number(maximum is 2,147,483,647): ");
        int number2 = Convert.ToInt32  (Console.ReadLine());
        int result = number1 / number2;
        Console.WriteLine("Is " + result + " your number?");`    
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Zawaad
  • 1
  • 1
  • Integers are whole numbers only, if you want to be able to output decimal numbers (like `7 / 2` would) you'll need to cast (one of both numbers) to a type that can represent a decimal number, something like `float` or `double` (or `decimal`), so `float result = (float) number1 / number2;`, you may run into weird behaivour doing that though, for more on that [Is floating point math broken?](https://stackoverflow.com/q/588004/9363973) – MindSwipe Jul 04 '22 at 06:45
  • 1
    But I'll need to vote to close this question as a duplicate of [Why does integer division in C# return an integer and not a float?](https://stackoverflow.com/questions/10851273/why-does-integer-division-in-c-sharp-return-an-integer-and-not-a-float) – MindSwipe Jul 04 '22 at 06:48
  • so thanks so much, i used double to do it, and it works perfectly now, thank u – Zawaad Jul 04 '22 at 06:50

1 Answers1

-1
// See https://aka.ms/new-console-template for more information
//here is your desire answer i hope
 Console.WriteLine("This is a division app");
Console.Write("Please input a whole number(maximum is 2,147,483,647): ");
int number1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please input another whole number(maximum is 2,147,483,647): ");
int number2 = Convert.ToInt32(Console.ReadLine());
float num1 = (float)number1;
float num2 = (float)number2;
float result = (float)(num1 / num2);
Console.WriteLine("Is " + result + " your number?");
HimonHimu
  • 104
  • 7