Hello all. Back yet again with another brain puzzler.
I'm having trouble with another playaround program, searched before posting, and cant find anything that really helps me with my specific problem.
NOTE: if you are willing to help me with this, then you MUST enter a year that would make you "13 to 18" years old.
More info: "If the user is a teenage (13-18) ask them to input a 3 letter word i.e. "cat"
output: "Original: "cat"
output: "Backwards: "tac"
problem: I can cout "cat" easy enough,but my backwards is a mess.
My current Output when I run the program:
Enter the year you were born:
2006
Enter your first and last name:
john doe
Hello john doe you are 15 years old.
So you are a teenager.
The first letter of your first name is: j
The last letter of your last name is: e
Enter a 3 letter word:
cat
Original: cat
Backwards:
Backwards: t
Backwards: a
Backwards: c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string fullname;
string word;
int year;
int cyear = 2021;
int i;
bool threelw;
cout << "Enter the year you were born: " << endl; //user enters year of birth.
cin >> year;
cout << "Enter your first and last name: " << endl;
cin.ignore();// ignores the white space between first name and last name.
getline(cin, fullname); //user enters first and last name seperated by a space.
cout << "Hello " << fullname << " you are " << cyear - year << " years old." << endl;
if (cyear - year <= 12)
{
cout << "So you are a child." << endl; // if they are 12 or younger, they're a child
}
if (cyear - year >= 13 && cyear - year <= 18)
{
cout << "So you are a teenager." << endl; // if they are 13 - 18 years old, they're a teenager
}
if (cyear - year > 18)
{
cout << "So you are an adult." << endl; // if they're older than 18, they're an adult
}
fullname.at(0) = tolower(fullname.at(0));
cout << "The first letter of your first name is: "; // outputs the first letter of first name.
cout << fullname[0] << endl;
cout << "The last letter of your last name is: "; // outputs the last letter of last name.
cout << fullname[fullname.length() - 1] << endl;
if (cyear - year >= 13 && cyear - year <=18) // if the user is a teenager, have them input a 3 letter word.
{
cout << "Enter a 3 letter word: " << endl; // input of 3 letter word.
cin >> word;
}
if (word.length() != 3)
{
cout << "You entered a word that is less than 3 letters." << endl; //if the word is less than 3, output error message.
threelw= false;
}
if (word.length() > 3)
{
cout << "You entered a word that is more than 3 letters." << endl; //if the word is more than 3, output error message.
threelw = false;
}
if (word.length() == 3) // if the word length is 3, output the original word, followed by the word backwards.
{
cout << "Original: " << word << endl;
}
for (int i = word.length(); i >= 0; --i)
{
cout << "Backwards: " << word[i] << endl;
}
}
|