dimanche 25 juin 2023

The program is not entering the if condition [duplicate]

I have recently started learning C++ and wanted to try something just for fun. But I ran into a problem. Here is the code:

#include <iostream>

int num;

void enter_code(int passcode) {
  std::string secret_knowledge = "E=mc2";

  if (passcode == 0310) {
    
    std::cout << secret_knowledge << "\n";
    
  } else {
    
    std::cout << "Sorry, incorrect!\n";
    
  }
}

int main() {
  
  std::cout <<"Enter pass\n";
  std::cin >>num;

 if(num==0310)
 {
    enter_code(0310);
 }
 else{
    enter_code(num);
 }


}

Even if I enter the correct passcode, the output is "Sorry, incorrect!. Where am I going wrong?

Aucun commentaire:

Enregistrer un commentaire