April 8th, 2005, 11:31 PM
|
#1 (permalink)
| | Senior Member
Join Date: Mar 2005 Location: oklahoma, US
Posts: 557
|
i do not get If statements at all in C++,
i use them like it says to and i get errors
let me show you Code: #include <iostream>
using namespace std;
int main()
{
if (5<4);
Execute the next statement;
{cout<<"HEY I UNDERSTAND IF's!!";}
cin.get();
}
__________________
RIP TKOP!!
|
| |
April 8th, 2005, 11:41 PM
|
#2 (permalink)
| | Ultimate Member
Join Date: Aug 2004 Location: SouthWest, Florida
Posts: 1,440
|
What is the (count<< part ??
other than that it seem fine, is this is , i mean there has to be an output how will you show the result.
__________________ MSI K8N Neo4 Platinum / A64X2 4800+ Toledo(Stock)
7900GTX 698mhz / 2GB Corsairs XMS PRO Dual
Hitachi SATA II (2x 250GB, 1x 500GB) ASUS G1 |
| |
April 8th, 2005, 11:43 PM
|
#3 (permalink)
| | Senior Member
Join Date: Mar 2005 Location: oklahoma, US
Posts: 557
|
(cout is changed but i dont know what you mean by
"i mean there has to be an output how will you show the result.
" |
| |
April 8th, 2005, 11:46 PM
|
#4 (permalink)
| | Ultimate Member
Join Date: Aug 2004 Location: SouthWest, Florida
Posts: 1,440
|
You said if 5<4. What is greater than 4? This cant be the complete code. and the output i mean, how are you going to show the "hey I know if statements". like in java its
system.out"BLAHBLAHBLAH" |
| |
April 8th, 2005, 11:50 PM
|
#5 (permalink)
| | Senior Member
Join Date: Mar 2005 Location: oklahoma, US
Posts: 557
|
with iostream, it shows it on command prompt, and why would you need something greater than 4, it shouldn't show the cout b/c it's false |
| |
April 8th, 2005, 11:54 PM
|
#6 (permalink)
| | Ultimate Member
Join Date: Aug 2004 Location: SouthWest, Florida
Posts: 1,440
|
oh ok,
you need an else or it will do nothing if the number is lees than 4.
I would show you an example but i forgot a lot about java, and java is simalar to c++.
yea try an else statement and write like "NOTTRUEBLAH" or anyother message to see if it is working.
Edit:
Some time I would script a program and keep getting errors because the program i use to type it f**ed up. SO I copy/ pasted on a new program with the exact same code and it worked, so try that too. |
| |
April 9th, 2005, 12:02 AM
|
#7 (permalink)
| | Ultimate Member
Join Date: Jan 2003 Location: MA / NH
Posts: 1,497
|
In Java a simple if statement would be like: Code: If (intNum < 4){
//Process code here
//intNum is less than 4
}
Else If (intNum > 6){
//Sample Else If
//intNum is greater than 6
}
Else{
//Sample Else code
//intNum is either 4, 5 or 6
} I’m sure it’s very similar to C++.
-Blaze
Last edited by Blazer06 : April 9th, 2005 at 12:05 AM.
|
| |
April 9th, 2005, 12:05 AM
|
#8 (permalink)
| | Ultimate Member
Join Date: Jun 2004 Location: Indianapolis, Indiana
Posts: 1,386
|
You included a semicolon after the if statement:
if(4<5);
{ statements
}
You can't have that semicolon ( ; ) there.
A proper C++ if statement: Code: #include <iostream.h>
int main(void)
{
int number=5;
if(number<10)
{
cout << "The statement is true!\n";
}
return 0;
}
__________________
Logic shall prevail.
|
| |
April 9th, 2005, 12:06 AM
|
#9 (permalink)
| | Ultimate Member
Join Date: Jan 2003 Location: MA / NH
Posts: 1,497
|
I don’t program C++, but what if you changed your if statement to this: Code: int main()
{
if (5 < 4){
//Execute the next statement;
cout<<"HEY I UNDERSTAND IF's!!";
cin.get();
}
}
-Blaze |
| |
April 9th, 2005, 12:07 AM
|
#10 (permalink)
| | Ultimate Member
Join Date: Jan 2003 Location: MA / NH
Posts: 1,497
| Quote: |
Originally Posted by FatalException You included a semicolon after the if statement:
if(4<5);
{ statements
}
You can't have that semicolon ( ; ) there. | That’s what I was thinking, but wasn’t sure if it was (which it is) the same as in Java.
Also, for reference, a simple Google showed this: http://msdn.microsoft.com/library/en...m/statem_9.asp
-Blaze |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |