Jump to content
  • Advertisement
Sign in to follow this  
ComputerProgrammer

Help a newbie in Visual C++

This topic is 4051 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, I was using C++ language (from the Microsoft Visual Studio 2005) to create a simple console application as following: #include <iostream> using namespace std; int main() { int value = 0; statement_01: cout << "Type in any integer value: "; cin >> value; if(value != 1 || value != 2) cout << "The value in the variable 'value' is not 1 ou 2"; else goto statement_01; cout << endl << endl << endl; } When I run it it does not work correctly because it should repeat all these statements if I typed "1" ou "2" values. But when I type in these either these values it finishs. Can someone help me?!

Share this post


Link to post
Share on other sites
Advertisement
Think about the logic in your 'if' statement, if needed choose a number for 'value' and work everything out by hand, step by step, and you'll see your problem.

Also, consider using a 'while' loop instead of an 'if' and a 'goto'.

Share this post


Link to post
Share on other sites
Your program doesn't work correctly because Your IF is logically wrong.
Look...

when You type "1" then you have :

IF ( 1 !=1 || 1 !=2 )
-------|----------|-------
-----false--||---true


after that You have

IF ( false or(||) true )
false || true gives you true

after that
IF (true) ...

As we know the IF executes when in () is TRUE.

So the conclusion is : Change the logical operations as OrangyTang said.

greetz

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!