TheJediSlayer
Posts: 164 +0
Well, I'm a beginner at C++ and I had a question to ask. It's about the \n and it messing up my code. I'm not sure why but when I tried to compile my program; it wouldn't go and gave me a bunch of errors. After trying to find out the problem, I finally got it, by removing \n in cout<<"Text to output"; it worked. However, I'm a bit confused as to why it worked before and not now. I am still using the same compiler as before, too.
Tutorials code:
This was my code:
Reference:
http://www.cprogramming.com/tutorial/lesson2.html
Any help would be much appreciated,
Tyler
Tutorials code:
#include <iostream>
using namespace std;
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
cin.ignore(); // Throw away enter
if ( age < 100 ) { // If the age is less than 100
cout<<"You are pretty young!\n"; // Just to show you it works...
}
else if ( age == 100 ) { // I use else just to show an example
cout<<"You are old\n"; // Just to show you it works...
}
else {
cout<<"You are really old\n"; // Executed if no other statement is
}
cin.get();
}
This was my code:
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Please enter your current age: ";
cin>> age;
cin.ignore();
if ( age = 100 ) {
cout<<"Wow, you are very young!";
}
else if ( age < 100 ) {
cout<<"You are very old!";
}
else {
cout<<"You did not input an answer!:";
}
cin.get();
}
Reference:
http://www.cprogramming.com/tutorial/lesson2.html
Any help would be much appreciated,
Tyler