I need to make a program in C++ in which I insert a number 'n' that's with 4 digits and it's a simple number, in the console and the console is showing me the multiplication of the certain number with 4 digits which I first needed to write.
I tried to write (n/!2) in order to make the program execute only if the number can't divide by 2 and the console showed "main.cpp:22:36: warning: division by zero [-Wdiv-by-zero]".
I've tried removing
(n /! 2) and the code got executed without a problem. I will be glad if someone can tell me how can I fix it.
#include <bits/stdc++.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
int getProduct(int n)
{
int product = 1;
while (n != 0) {
product = product * (n % 10);
n = n / 10;
}
return product;
}
int main()
{
int n;
cout << "insert n ";
cin >> n;
if (n >= 1000 && n <= 9999 && n /! 2) {
cout << (getProduct(n));
}
}