[ create a new paste ] login | about

Link: http://codepad.org/pWCQcrX8    [ raw code | fork ]

JGranger95 - C++, pasted on Dec 31:
//This is a C++ program designed to test multiple features of C++
#include <iostream>
#include <cctype>
#include <algorithm>
#include <clocale>
#include <string>

using namespace std; //use the standard namespace

int main()
{
    //define integers and string variables
    string answ;
    int cyear, cday, cmonth, mborn, dborn, yborn, age;


    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;

    //if the month/day has passed, you are (age) years old. if not, you are age - 1
   if((cmonth - mborn) > 0)
        {
                cout << "You are currently " << age << " years old... correct? (yes/no)\n";
        }
//----------------------------------------------------------------------------------//
    else if((cmonth - mborn) == 0)
        {
            if((cday - dborn) >= 0)
            {
                cout << "You are currently " << age << " years old... correct? (yes/no)\n";
            }
            else
            {
                cout << "You are currently " << --age << " years old.... correct? (yes/no)\n";
            }
        }
//----------------------------------------------------------------------------------//
    else if(((cmonth - mborn) < 0) || ((cday - dborn) < 0 ))
        {
             cout << "You are currently " << --age << " years old.... correct? (yes/no)\n";
        }

    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"


    while((answ != "yes") && (answ != "no"))
        {
            cout << "Your answer was not 'yes' or 'no', please fix this immediately!\n";
            cout << "Was the calculation of your age correct? ";
            cin >> answ;
            transform ( answ.begin(), answ.end(), answ.begin(), ptr_fun(::tolower) );
        }

    if(answ == "yes")
        {
            cout << "That's pretty cool, I bet you didn't think I was that smart! \n";
        }

    else
        {
            cout << "Oh dear.. you've tricked me! How can that be possible?! \n";
        }

}


Create a new paste based on this one


Comments: