I wrote a function that tells you how many days you've lived so far. I can't help having the feeling that this code could be cleaner. Here's what i've done:
Code:#include <iostream> using namespace std; int doIt(int yearBorn) { int currentYear = 2010; int daysInAYear = 365; int yearCount = yearBorn; int differenceOfYears; int result; int x; for(x=0;yearCount != currentYear; x++,yearCount++) { differenceOfYears = x + 1; } result = differenceOfYears * daysInAYear; return result; } int main() { cout<<"You've lived "<<doIt(1990)<<" days."; cin.get(); }



LinkBack URL
About LinkBacks



