我在c++中使用If else语句,我得到了相反的答案.查看更多信息

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

本文关键字:答案 信息 c++ If else 语句 我在      更新时间:2023-10-16

Code::Blocks 10.06

我用下面的代码编写了一个程序来检查数字1是否能被数字2整除,然而,我输入数字1为8,数字2为4,它显示数字1不能被数字2整除,下面是我的代码,我也有程序运行的照片。关于我的程序

请告诉我是什么错误,请,我需要学习这个程序,我有一些目标:

#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;
}

将=替换为== i.e.

if(d==0)
{
  cout<<"somethingn";
}