-
question
Im using the tutorials on this site and im using Dev-C++ and whenever i insert the thing below it will noit compile and i copied and pasted it from the tutorials
Code:
#include <iostream.h>
int main() //Most important part of the program!
{
int age; //Need a variable...
cout<<"Please input your age: "; //Asks for age
cin>>age; //The input is put in age
if(age<100) //If the age is less than 100
{
cout<<"You are pretty young!"; //Just to show it works
}
else if(age==100) //I use else just to show an example
{
cout<<"You are old"; //Just to show you it works...
}
else
{
cout<<"You are really old"; //Executed if no other statement is executed
}
return 0;
}
-
> #include <iostream.h>
Change this to
#include <iostream>
using namespace std;
And be more specific about "will not compile", by including actual error messages
-
When using source code that may have been written on other operating systems you may have to tweak the includes and namespaces, as well as, your environmental pathing. Generally, compilers do a really good job in telling you what is wrong and you should, just my thoughts, include a little snip from the error that you have questions about. This will aid the other members in trying to answer your question.
DeadPoet
-
why do u use the brackets after if and else if
you dont need it since it's only one line (ONLY ONE STATEMENT)
-
It's sort of like tapping your feet when you start to play music/sing, or using your fingers when you start to count. Using braces to delineate the body of all if/else/while statements is easier to learn than the exception of being able skip them if there is just a single line to the body.
Continue to use them until such time as you find them inconvenient. They aren't wrong, even if they seem unnecessary for a more experienced programmer.
-
Rock on my brother Elad! It is much easier to read when someone uses correct bracketing. Then I do not have to stop and think about what the author/developer is trying to say. You know, did they mean to have the second or third statement used with the context of the conditional statement.
Rock On!
DeadPoet