Q:

Revise your program to throw an exception if the second number is zero

0

Revise your program to throw an exception if the second number is zero. Test your program with a zero input to see what happens on your system if you don’t catch an exception.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
#include <stdexcept>

int main() {
  int a, b;
  std::cin >> a >> b;
  if (b == 0)
    throw std::runtime_error("Divide by 0.");
  std::cout << a / b << std::endl;

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now