[Noob Needing Help] Not too sure I understand!
Hey all, so I'm currently in my last year in school and want to go down the career path of programming. So I decided to begin learning early. I want to learn C++ and have followed lessons 1 and 2 on this site. However when coming to test my skills I'm currently stuck and don't know whether or not I've understood correctly.
Code:
#include <iostream>
using namespace std;
int main()
{
int age;
int current_year = 2012;
cout<<"Please enter your age: "; //Asks for Age
cin>> age; //Recives user input as their age
cin.ignore();
//Repeats age then works out when the person was born by taking the age away from 2012 or 2011 incase their birthday hasn't came around yet
cout<<"Your age is: "<< age <<" which mean you where either born in "<< current_year - age <<" or "<< (current_year - 1) - age<<"\n";
if (age < 10) //Asks if your less than 10 years old, then tells you that you're pretty young
{
cout<<"You are pretty young!";
}
else if (age > 10 && < 20) //Asks if you are between 10 and 20 and then tells you that you're a teen
{
cout<<"You are a teen!";
}
else if (age > 20 && < 50) //Asks if you are between 20 and 50 and then tells you that you're middle-aged
{
cout<<"You middle aged";
}
else if (age > 50) //Asks that if you are over 50, and then tells you that you're quite old
{
cout<<"You are quite old!";
}
}
This is the current program I am trying to write, where you enter your age in, it tells you what year you may have been born in the says where your young, old, or middle aged.
However I am getting a few problems:
1. When trying to run the program it is saying that:
Code:
else if (age > 10 && < 20)
{
...
}
else if (age > 20 && < 50)
{
...
}
is incorrect.
2. That when I press enter it goes through the whole program, where as I want you to enter you name, press enter, it tells you there year, press enter, it tells you young, old, etc.
Any help that you guys can offer would be a joy.
Thanks in advance
// Kegs