Hi folks,
I'm very new to C++, only started learning it tonight, but I learn quite quickly (luckily).
So far as part of a tutorial I made a basic program that asks for the users age, then returns a responce, depending on the number the user inputted. Which is pretty basic, I know.
for this I used (c++)
[code=C]
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Please input your age: ";
cin>> age;
cin.ignore();
if ( age < 13 ) {
cout<<"You are pretty young!\n";
}
else if ( age == 13) {
cout<<"Ooh, you're a teenager now!!\n";
}
else if ( age < 15) {
cout<<"Still a teenager, aye?\n";
}
else if ( age == 16) {
cout<<"Ooh, sweet sixteen, is it? Not so young and innocent now, are you!\n";
}
else if ( age < 39) {
cout<<"Getting older now, aren't you. Go you!\n";
}
else if ( age == 40) {
cout<<"Congratu lations! Life starts at 40, you know!\n";
}
else if ( age < 99) {
cout<<"Getting on a bit, aren't you?\n";
}
else if ( age == 100 ) {
cout<<"A whole century, wow!\n";
}
else {
cout<<"Don't be silly, stop lying. You're not that old!\n";
}
{
cout<<"\n\n\n\n[Please press Enter to exit]\n";
}
cin.get();
}[/code]
Which is fine, when they input an integer. but how would I adapt it (ignore the if statements) for if they were to enter a string, for a name, such as "Sam" or "James" or something? Would this be possible?
Sam
I'm very new to C++, only started learning it tonight, but I learn quite quickly (luckily).
So far as part of a tutorial I made a basic program that asks for the users age, then returns a responce, depending on the number the user inputted. Which is pretty basic, I know.
for this I used (c++)
[code=C]
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Please input your age: ";
cin>> age;
cin.ignore();
if ( age < 13 ) {
cout<<"You are pretty young!\n";
}
else if ( age == 13) {
cout<<"Ooh, you're a teenager now!!\n";
}
else if ( age < 15) {
cout<<"Still a teenager, aye?\n";
}
else if ( age == 16) {
cout<<"Ooh, sweet sixteen, is it? Not so young and innocent now, are you!\n";
}
else if ( age < 39) {
cout<<"Getting older now, aren't you. Go you!\n";
}
else if ( age == 40) {
cout<<"Congratu lations! Life starts at 40, you know!\n";
}
else if ( age < 99) {
cout<<"Getting on a bit, aren't you?\n";
}
else if ( age == 100 ) {
cout<<"A whole century, wow!\n";
}
else {
cout<<"Don't be silly, stop lying. You're not that old!\n";
}
{
cout<<"\n\n\n\n[Please press Enter to exit]\n";
}
cin.get();
}[/code]
Which is fine, when they input an integer. but how would I adapt it (ignore the if statements) for if they were to enter a string, for a name, such as "Sam" or "James" or something? Would this be possible?
Sam
Comment