Division safety
In C++ dividing by 0 leads to the program crashing.
Using only if statements for the logic; make a division calculator that takes 2 inputs and divides the first input by the second. Add an if statement that warns the user if their second input is 0.
You can output the answer if the second input is not 0.
Answer
#include <iostream>
int main()
{
std::cout << "Input the number you want to divide followed by the number you want to divide by. (seperated by space).\n";
float input1, input2;
std::cin >> input1 >> input2;
if (input2 == 0)
{
std::cout << "You cannot divide by 0. Please input a non-zero number as your divident.\n";
}
if (input2 !=0)
{
std::cout << input1 << "/" << input2 << " = " << input1/input2;
}
}