Jump to content
Sign in to follow this  
buskmann

Spørsmål om if og &&

Recommended Posts

whoops... litt rask :blush:

 

Edit: Prøv dette..

 

#include <iostream>
using namespace std;

int main() {
int a=200, b=200;
cout << (a < 50) << endl;
cout << (50 < a) << endl;
cout << (50 < a < 100) << endl;
cout << (50 < a < 0) << endl;
cout << ((50 < a < 100) && (50 < b < 100)) << endl;

}

gir:

0

1

1 (50<a evalueres til 1, som er mindre enn 100)

0 (50<a evalueres til 1, som ikke er mindre enn 0)

1

Edited by JBlack

Share this post


Link to post
Hvorfor utføres this->Close() i denne?

   int a = 200, b = 200;
  if ((50 < a < 100) && (50 < b < 100)){
     this->Close();
  }

Fordi du ikke kan bruke (50 < a < 100), men i stedet må delen den opp enda mer slik at den blir ((50 < a) && (a < 100)), da det er to forskjellige tester...

Share this post


Link to post

Siden JBlack endret sitt innlegg får jeg vel endre dette også..

 

 

Litt testing viser at coden

if(tall1 < variabel < tall2) { kode }

vil gi utføre "kode" så lenge variabelen er større enn tall1 eller mindre enn tall2.

Edited by Mr.Garibaldi

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...