My assignment is to create a program that calculates the number of days from Jan 1, 2004 to a date in the year the user enters. It has to recognize invalid dates (such as feb 30) and the user should prompt the user to try again until they make a valid entry.
I really have no idea what I am doing, but I hope somebody can at least guide me through to help me set up the valid date recognitions. This is what I came up with so far. I know it is probably nowhere near correct, but I tried!
Code:#include <iostream> using namespace std; const char * const months [12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; const int days[12] = {31,29,31,30,31,30,31,31,30,31,30,31}; int main() { int months; int days; cout << "This program calculates the number of days from Jan 1, 2004 to a date in the year 2004 that you specify." << endl; cout << "Please enter a month (1-12): "; cin >> months; while (months<13) {cout<< months << "is not a valid entry for the month. Please enter a value between 1 and 12: "; cin >> months;} cout << "Please enter a day of the month: "; cin >> days; while (days[months-1], days[months-3], days[months-5], days[months-7], days[months-8], days[months-10], days[months-12] <=31; days[months-2]<=29; days[months-4], days[months-6], days[months-9], days[months-11] <=30) {cout << days << "is not a valid day in the month of February. Please enter a value between 1 and " << days[months-1] << ": "; cin >> days; } return 0; }



LinkBack URL
About LinkBacks


