First off, the program is part of an assignment due tomorrow for my intro to C++ class. Here is the assignment prompt:
CSIT 575 – Programming Fundamentals for Computer Science Lab #3A
Objectives:
To learn to code, compile and run a program containing SELECTION structures
Assignment:
A. Plan and code a C++ program utilizing the if-then-else structure to solve the following:
B. Write an interactive C++ program to determine the day of the week for any given date from 1900-2099. Following are the steps you should use:
C. Input the date in 3 separate parts, month, day and 4-digit year. Error check to make sure the month is between 1 and 12, the day between 1 and 31, and the year between 1900-2099. If there is an error, identify the type of error and stop the program.
D. If the data is good, divide the last two digits of the year by 4. Store the quotient (ignoring the remainder) in Total. For example, for 1983, divide 83 by 4 and store 20 in Total.
E. Add the last 2 digits of the year to Total.
F. Add the two digits of the day of the month to Total.
G. Using the following table, find the "value of the month" and add it to Total.
January = 1 May = 2 September = 6
February = 4 June = 5 October = 1
March = 4 July = 0 November = 4
April = 0 August = 3 December = 6
H. If the year is 2000 or later, add 6. If the year is 2000 exactly and the month is January or February, subtract 1.
I. Then, determine if the year is a leap year. A leap year is divisible by 4 but not divisible by 100. If it is a leap year and the month is January or February, subtract 1. (The year 2000 is NOT a leap year).
J. Find the remainder when the Total is divided by 7. Use the remainder to find the day:
1= Sunday 3 = Tuesday 5 = Thursday
2 = Monday 4 = Wednesday 6 = Friday
0 = Saturday
Input
Your three initials, the month, day, and 4-digit year of the date to analyze.
Output
All of the input fields, a message if the data is OK and the day of the week of the date. Output the date and the appropriate error message if the data is bad.
Turn in
Program listing and program output.
Test today’s date, your birthdate, and the dates your instructor gives you and error conditions.
I'm having trouble with the output. I am trying to get an output message of "Data is NOT OK" if the day is not between 1-31, month not between 1-12, and year not between 1900-2099 and an output of "Data is OK" if the day is between 1-31, month between 1-12, year between 1900-2099. The output always comes out as "Data is OK". I think it might be a precedence problem.
This is what I have so far. I know its a bit messy, but Im still new to C++. Any help would be appreciated! primarily on the else/ else-if statement.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <sstream>
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string initials;
string mystring;
int month;
int day;
int year;
int wtf;
cout << "Enter your initials: ";
cin >> initials;
cout << "Enter the month: ";
cin >> month;
cout << "Enter the day: ";
cin >> day;
cout << "Enter the year: ";
cin >> year;
if (month >12 && day >31 && year >2099)
cout << "Data is NOT OK";
else if (month >=1 <=12 && day >= 1 <=31 && year >= 1900 <=2099)
cout << "Data is OK";
cout << endl;
cout << "wtf is: ";
cin >> wtf;
}
| |