水曜日, 10月 24, 2007

自找麻煩的

寫了計算月、日的日子差的東西,不過還有很多bug。

#include <iostream>
using namespace std;

void count(int intMonthN, int intMonthN2, int intDayN, int intDayN2);

void fault();

void main(){
int intMonthN, intMonthN2, intDayN, intDayN2, intSum, intSum2, intWeek, intWeek2;
char charCount;

charCount = 'Y';

while(charCount != 'N'){

cout << "Please enter the month: ";
cin >> intMonthN;
cout << "Please enter the day: ";
cin >> intDayN;

cout << "Please enter the other month: ";
cin >> intMonthN2;
cout << "Please enter the other day: ";
cin >> intDayN2;

if((intMonthN >= 1) && (intMonthN <= 12)){
if(intMonthN == 2){
if((intDayN >= 1) && (intDayN <= 28)){
if((intMonthN2 >= 1) && (intMonthN2 <= 12)){
if(intMonthN2 == 2){
if((intDayN2 >= 1) && (intDayN2 <= 28)){
count(intMonthN, intMonthN2, intDayN, intDayN2);
}else{
fault();
}
}else{
if((intDayN2 >= 1) && (intDayN2 <= 31)){
count(intMonthN, intMonthN2, intDayN, intDayN2);
}else{
fault();
}
}
}else{
fault();
}
}else{
fault();
}
}else{
if((intDayN >= 1) && (intDayN <= 31)){
if((intMonthN2 >= 1) && (intMonthN2 <= 12)){
if(intMonthN2 == 2){
if((intDayN2 >= 1) && (intDayN2 <= 28)){
count(intMonthN, intMonthN2, intDayN, intDayN2);
}else{
fault();
}
}else{
if((intDayN2 >= 1) && (intDayN2 <= 31)){
count(intMonthN, intMonthN2, intDayN, intDayN2);
}else{
fault();
}
}
}else{
fault();
}
}else{
fault();
}
}
}else{
fault();
}

cout << "\nDo you want to do once again?(Y to do again, N to quit)";
cin >> charCount;
}

system("pause");
}

void count(int intMonthN, int intMonthN2, int intDayN, int intDayN2){
int intSum, intSum2, intWeek, intWeek2;

if(intMonthN == 1){
intSum = intDayN;
}else if(intMonthN == 2){
intSum = 31 + intDayN;
}else if(intMonthN == 3){
intSum = 31 + 28 + intDayN;
}else if(intMonthN == 4){
intSum = 31 + 28 + 31 + intDayN;
}else if(intMonthN == 5){
intSum = 31 + 28 + 31 + 30 + intDayN;
}else if(intMonthN == 6){
intSum = 31 + 28 + 31 + 30 + 31 + intDayN;
}else if(intMonthN == 7){
intSum = 31 + 28 + 31 + 30 + 31 + 30 + intDayN;
}else if(intMonthN == 8){
intSum = 31 + 28 + 31 + 30 + 31 + 30 + 31 + intDayN;
}else if(intMonthN == 9){
intSum = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + intDayN;
}else if(intMonthN == 10){
intSum = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + intDayN;
}else if(intMonthN == 11){
intSum = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + intDayN;
}else if(intMonthN == 12){
intSum = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + intDayN;
}

if(intMonthN2 == 1){
intSum2 = intDayN2;
}else if(intMonthN2 == 2){
intSum2 = 31 + intDayN2;
}else if(intMonthN2 == 3){
intSum2 = 31 + 28 + intDayN2;
}else if(intMonthN2 == 4){
intSum2 = 31 + 28 + 31 + intDayN2;
}else if(intMonthN2 == 5){
intSum2 = 31 + 28 + 31 + 30 + intDayN2;
}else if(intMonthN2 == 6){
intSum2 = 31 + 28 + 31 + 30 + 31 + intDayN2;
}else if(intMonthN2 == 7){
intSum2 = 31 + 28 + 31 + 30 + 31 + 30 + intDayN2;
}else if(intMonthN2 == 8){
intSum2 = 31 + 28 + 31 + 30 + 31 + 30 + 31 + intDayN2;
}else if(intMonthN2 == 9){
intSum2 = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + intDayN2;
}else if(intMonthN2 == 10){
intSum2 = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + intDayN2;
}else if(intMonthN2 == 11){
intSum2 = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + intDayN2;
}else if(intMonthN2 == 12){
intSum2 = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + intDayN2;
}

if(intSum > intSum2){
intWeek = (intSum - intSum2) / 7;
intWeek2 = (intSum - intSum2) % 7;
if((intWeek == 0) || (intWeek == 1)){
if((intWeek2 == 0) || (intWeek2 == 1)){
cout << "There is " << intWeek << " week and " << intWeek2 << " day\n";
}else{
cout << "There is " << intWeek << " week and " << intWeek2 << " days\n";
}
}else{
if((intWeek2 == 0) || (intWeek2 == 1)){
cout << "There are " << intWeek << " weeks and " << intWeek2 << " day\n";
}else{
cout << "There are " << intWeek << " weeks and " << intWeek2 << " days\n";
}
}
}else if(intSum2 > intSum){
intWeek = (intSum2 - intSum) / 7;
intWeek2 = (intSum2 - intSum) % 7;
if((intWeek == 0) || (intWeek == 1)){
if((intWeek2 == 0) || (intWeek2 == 1)){
cout << "There is " << intWeek << " week and " << intWeek2 << " day\n";
}else{
cout << "There is " << intWeek << " week and " << intWeek2 << " days\n";
}
}else{
if((intWeek2 == 0) || (intWeek2 == 1)){
cout << "There are " << intWeek << " weeks and " << intWeek2 << " day\n";
}else{
cout << "There are " << intWeek << " weeks and " << intWeek2 << " days\n";
}
}
}else if(intSum2 == intSum){
cout << "The date is the same.\n";
}
}

void fault(){
cout << "Please enter the correct date(month[1 - 12] and day[1 - 31])\n";
}

0 件のコメント: