codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
//This is a C++ program designed to test multiple features of C++ #include <iostream> #include <stdio.h> #include <algorithm> //included to use the transform() command using namespace std; //use the standard namespace int main() { //define integers and string variables string answ; int cyear, cday, cmonth, mborn, dborn, yborn, age, ttl, xxl; cout << "Hello! I have a few questions! Answer them all in NUMBER values!\n" << endl; cout << "The 'XX' represents the expected input format. " << "\n \n"; //birth information cout << "What month were you born in? XX "; cin >> mborn; cout << "What day of the month were you born on? XX "; cin >> dborn; cout << "What year were you born? XXXX "; cin >> yborn; //current year information cout << "\nWhat is the current month? XX "; cin >> cmonth; cout << "What is the current day of the month? XX "; cin >> cday; cout << "What is the current year? XXXX "; cin >> cyear; //calculate the year difference age = cyear - yborn; ttl = cmonth - mborn; xxl = cday - dborn; //if the month/day has passed, you are (age) years old. if not, you are age - 1 if((ttl >= 0) && (xxl >= 0)) { cout << "You are currently " << age << " years old... correct? (yes/no)\n"; } else if((ttl < 0) || (xxl < 0 )) { cout << "You are currently " << --age << " years old... correct? (yes/no)\n"; } //asks user if the calculations are correct and outputs accordingly cin >> answ; transform ( answ.begin(), answ.end(), answ.begin(), ptr_fun(::tolower) ); //turns answer to lowercase //by making the answer lowercase, you can test "yes", rather than "yes","Yes", "YES", "yEs" if(answ == "yes") { cout << "That's pretty cool, I bet you didn't think I was that smart! \n"; } else if((answ != "yes") || (answ != "no")) { cout << "Please enter yes/no! Not some silly alternative! \n\n"; if((ttl >= 0) && (xxl >= 0)) { cout << "You are currently " << age << " years old... correct? (yes/no)\n"; } else if((ttl < 0) || (xxl < 0 )) { cout << "You are currently " << --age << " years old... correct? (yes/no)\n"; } cin >> answ; transform ( answ.begin(), answ.end(), answ.begin(), ptr_fun(::tolower) ); } else { cout << "Oh dear.. you've tricked me! How can that be possible?! " <<endl; } }
Private
[
?
]
Run code
Submit