TheMighty TheMighty - 1 month ago 5
C++ Question

I used If else statement in C++, and i got opposite answer.. Check for more in info

Code::Blocks 10.06

i used the following code to make a program to check whether the number 1 is divisible by number two or not however, i entered number 1 as 8, number two as 4 and it showed number one is not divisible by number two, below is my code, and i also have the program runned's photo.. about my program

please tell me what is the error, please, i need to learn this progam, i have some targets:

#include <iostream>

using namespace std;

int main()
{
int a, b, d;

cout << "Hello guys" << endl;

cout << "Bucky's Student21 here" << endl;
cout << "today we are going to divide two numbers, and going to check whether one is divisible by other or not \n";

cout << "If the number 1 is divisible by number 2, i will recognize it \n";

cout << "enter number 1 \n";
cin >> a;

cout << "enter number 2 \n";
cin >> b;

d = a % b;
if (d = 0) {
cout << "number 1 is divisible by number 2 \n";
}
else {
cout << "number 1 is not divisible by number 2 \n ";
}
cout << "Hence now as you got to know whether the number 1 is divisible by number 2 or not \n";

return 0;
}

Answer

Just replace = with == i.e.

if(d==0)
{
  cout<<"something\n";
}