jeudi 11 juillet 2019

why is this piece of code always displaying "LEAVE!" even with the two parameters shown?

Please ignore the context of this code. The idea was the function named shop would take the two parameters (money_in_pocket,age) and determine if these values would let them into a Rolex store. However, even when the parameters meet the requirements of the if statement in the function "shop", the program proceeds to output "Leave!"- meaning leave the store.

As you may have noticed i'm new to the language, so any help would be much appreciated.

I've tried making the parameters far larger than the if statements asks for them to be. This outputted "leave!" so i tried parameters that did not meet the requirements and the same output was enter code heredisplayed...

#include <iostream>

using namespace std;

class rolex{

   public:
      bool shop(int x, int y){
         if((x >= 5000 && y>= 18)||(x>=5000 && y<18)){
            bool enterence = true;
         }else{
            bool enterence = false;
         };
         return enterence;
      }
   private:
      bool enterence;
};

int main()
{
   rolex objj;

   if( objj.shop(5000, 18) == true){
      cout<<"you may enter"<<endl;
   }else{
      cout<<"LEAVE"<<endl;
   }
   return 0;
}

Aucun commentaire:

Enregistrer un commentaire