-3

I'm trying to divide by negative numbers where both the quotient and divisor are negative. However it returns 0 when done like this.

#include <iostream>
using namespace std;

int main() {
double m = -46 / -120;
cout << m << endl;
}

output: 0

Chiru
  • 1
  • 2

1 Answers1

2

As pointed in the comment, it is true that your instance of code will produce 0 even for a Positive number. So it should be like this:

#include<iostream>

int main() {
   double m = -46.0 / -120.0;
   std::cout << m << '\n';
}
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
Abhishek Dutt
  • 1,308
  • 7
  • 14
  • 24