All pastes #162436 Raw Edit

Unnamed

public cpp v1 · immutable
#162436 ·published 2006-09-06 14:40 UTC
rendered paste body
#include "iostream"using namespace std;int askint (string question){        int answer;        cout << question << "? ";        cin >> answer;        cout << "[" << answer << "]" << endl;        return answer;}string askstring (string question, int minimum = 1){        string answer = "";        while ( answer.length() < minimum)        {                cout << question << "? ";                cin >> answer;        }        cout << "[" << answer << "]" << endl;        return answer;}int main(){        int born;        int now;        int age;        bool validage=false;        bool validsex=false;        bool validmar=false;        string first;        string last;        string year;        string sex;        string married;        string name;        first = askstring("Your first name",3);        first[0] = toupper(first[0]);        last = askstring("Your last name");        last[0] = toupper(last[0]);        while ( validage == false)        {                born = askint("What year were you born (ex. 1979)");                now = askint("What year is it now (ex. 2006)");                if ( born <= now)                {                        validage=true;                }                else                {                        cout << "Thats impossible! You can't be less than 0 years old!" << endl;                }        }        age = now - born ;        if (age == 1)        {                year = "year" ;        }        else        {                year = "years" ;        }        while (validsex == false)        {                sex = askstring("Your sex [m/f]");                if (sex == "m" || sex == "f")                {                        validsex=true;                }                else                {                        cout << "Type m or f only." << endl;                }        }        if (age > 18)        {                while (validmar ==false)                {                        married = askstring("Are you currently married ? [y/n] :");                        if (married == "y" || married =="n")                        {                                validmar=true;                        }                        else                        {                                cout << "Type y or n only." << endl;                        }                }        }        else        {                cout << "I don't suppose you're married." << endl ;        }        if (age < 16)        {                name = "Young. " ;        }        else        {                if (sex == "m")                {                        name = "Mr. " ;                }                else                {                        if (sex == "f" && married == "y")                        {                                name = "Mrs. " ;                        }                        else                        {                                name = "Ms. " ;                        }                }        }        cout << "Hello again " <<  name << " " << last << "," << endl ;        cout << first << ", you're " << age << " " << year << " old." << endl ;        return 0;}