[ create a new paste ] login | about

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

JGranger95 - C++, pasted on Dec 30:
//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;


    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) && ((cday - dborn) >= 0))
        {
             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";
        }

    //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
        {
            cout << "Oh dear.. you've tricked me! How can that be possible?! \n";
        }

}


Create a new paste based on this one


Comments: