Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 If Statements
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sockoo




PostPosted: Sun Oct 01, 2006 12:22 pm   Post subject: If Statements

Well first off i'd like to introduce my self and say that .. i'v just started to learn C ++ and obviously sense im here i need a bit of guidence

code:

#include<IOSTREAM.H>

void main(void)
  {
     float value;
     cout << "please enter in any value" << endl;
     cin >> value;
     if (value > 0);
     cout << "the entered value is greater than 0" <<endl;

     if (value <100);
     cout << "the entered value is less than 100" << endl;
     if (value > 50 & value < 500) ;
     cout << "the entered value is greater than 50 and less than 500" << endl;
     if (value != 7 & value != 10.5) ;
     cout << "the entered value is not 7 and not 10.5" <<endl;
     if (value > -5 & value < 5)  ;
     cout << "the entered value is greater then -5 and less than 5" <<endl;
     return 0;
  }


In the program just listed i want to be able to recieve a value from the user and then decide wiether or not the value is any of the if statements. But it doesnt seem to work , where am i going wrong ?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Oct 01, 2006 12:28 pm   Post subject: Re: If Statements

sockoo wrote:
if (value <100);

the semicolon ; terminates the statement
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
wtd




PostPosted: Sun Oct 01, 2006 12:35 pm   Post subject: (No subject)

A suggestion on how to avoid this kind of confusion:

Just because you don't always have to use the braces, that does not mean you shouldn't use them.
md




PostPosted: Sun Oct 01, 2006 4:30 pm   Post subject: (No subject)

Or, if you don't use braces at the very least use proper formating. Indenting the code to be executed if the condition is true helps make it more obvious what things are.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: