Hello People,
I need help because i just need to figure out whats wrong with the code i wrote for my program.. i tried to figure it out but i'm stuck. So here it is and i would appreciate it if someone can set me strait. Thanx alot.
Well here it is..
I am writing a program that computes the number of days between two dates.
It gives me a couple of error messages.
I don't know what i'm not using write or what i'm doing wrong!!
Please help me... Thanx again.
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstring>
using namespace std;
int main(int)
{
const int YEAR= 365;
int i;
string inMonth1;
int inMonth1Int;
string inDay1;
int inDay1Int;
string inYear1;
int inYear1Int;
string inEra1;
string inMonth2;
int inMonth2Int;
string inDay2;
int inDay2Int;
string inYear2;
int inYear2Int;
string inEra2;
char inMonth1Char;
char inMonth2Char;
int date1;
int date2;
bool badInput;
long double in1;
long double in2;
while (badInput==false)
{
while (inMonth1!="quit" &&inDay1!="quit" &&inYear1!="quit" && inEra1!="quit"
&&inMonth2!="quit" &&inDay2!="quit" &&inYear2!="quit" && inEra2!="quit")
{
cout << "This program calculates the number of days between two dates."<< endl;
cout << "Please enter the dates using only the following format:"<< endl;
cout << "Month's abreviation, day, year, BC or AD" << endl;
cout << "Then press enter, and the next date"<< endl;
cout << "Example:"<< endl << "Jun 29 2500 BC (Enter)"<< endl<<"Jun 29 1238 AD (Enter)" << endl;
cout << "To quit, type the word 'quit' and enter."<< endl;
cout << "For the year of Jesus' death exactly, please type 0 for the year." << endl;
cout << "We're sorry, no other format can be accepted."<< endl;
cin.ignore('\n') >> inMonth1 >> inDay1 >> inYear1 >> inEra1 >> inMonth2 >> inDay2 >> inYear2 >> inEra2;
i=inMonth1.length();
while (i>0)
{
inMonth1[i]=tolower(inMonth1[i]);
i--;
}
i=0;
i=inMonth2.length();
while (i>0)
{
inMonth2[i]=tolower(inMonth2[i]);
i--;
}
if(inMonth1!="jan"&&inMonth1!="feb"&&inMonth1!="mar"&&inMonth1!="apr"&&inMonth1!="may"&&inMonth1!="jun"&&inMonth1!="jul"&&inMonth1!="aug"&&inMonth1!="sep"&&inMonth1!="oct"&&inMonth1!="nov"&&inMonth1!="dec")
badInput=true;
if (inMonth1=="jan")
inMonth1Char='a';
if (inMonth1=="feb")
inMonth1Char='b';
if (inMonth1=="mar")
inMonth1Char='c';
if (inMonth1=="apr")
inMonth1Char='d';
if (inMonth1=="may")
inMonth1Char='e';
if (inMonth1=="jun")
inMonth1Char='f';
if (inMonth1=="jul")
inMonth1Char='g';
if (inMonth1=="aug")
inMonth1Char='h';
if (inMonth1=="sep")
inMonth1Char='i';
if (inMonth1=="oct")
inMonth1Char='j';
if (inMonth1=="nov")
inMonth1Char='k';
if (inMonth1=="dec")
inMonth1Char='l';
inDay1Int=atoi(inDay1);
inYear1Int=atoi(inYear1);
inDay2Int=atoi(inDay2);
inYear2Int=atoi(inYear2);
switch (inMonth1Char)
{
case 'a':
if(inDay1Int>0&&inDay1Int<32)
{
inMonth1Int=31;
break;
}
else
badInput=true;
case 'b':
if(inYear1Int%4==0)
{
if(inDay1Int>0&&inDay1Int<30)
{
inMonth1Int=29;
break;
}
else
badInput=true;
}
else
{
if(inDay1Int>0&&inDay1Int<29)
{
inMonth1Int=28;
break;
}
else
badInput=true;
}
case 'c':
if(inDay1Int>0&&inDay1Int<32)
{
inMonth1Int=31;
break;
}
else
badInput=true;
case 'd':
if(inDay1Int>0&&inDay1Int<31)
{
inMonth1Int=30;
break;
}
else
badInput=true;
case 'e':
if(inDay1Int>0&&inDay1Int<32)
{
inMonth1Int=31;
break;
}
else
badInput=true;
case 'f':
if(inDay1Int>0&&inDay1Int<31)
{
inMonth1Int=30;
break;
}
else
badInput=true;
case 'g':
if(inDay1Int>0&&inDay1Int<32)
{
inMonth1Int=31;
break;
}
else
badInput=true;
case 'h':
if(inDay1Int>0&&inDay1Int<32)
{
inMonth1Int=31;
break;
}
else
badInput=true;
case 'i':
if(inDay1Int>0&&inDay1Int)
{
inMonth1Int=30;
break;
}
else
badInput=true;
case 'j':
if(inDay1Int>0&&inDay1Int<32)
{
inMonth1Int=31;
break;
}
else
badInput=true;
case 'k':
if(inDay1Int>0&&inDay1Int<31)
{
inMonth1Int=30;
break;
}
else
badInput=true;
case 'l':
if(inDay1Int>0&&inDay1Int<32)
{
inMonth1Int=31;
break;
}
else
badInput=true;
badInput=true;
}
switch (inMonth2Char)
{
case 'a':
if(inDay2Int>0&&inDay2Int<32)
{
inMonth2Int=31;
break;
}
else
badInput=true;
case 'b':
if(inYear2Int%4==0)
{
if(inDay2Int>0&&inDay2Int<30)
{
inMonth2Int=29;
break;
}
else
badInput=true;
}
else
{
if(inDay2Int>0&&inDay2Int<29)
{
inMonth2Int=28;
break;
}
else
badInput=true;
}
case 'c':
if(inDay2Int>0&&inDay2Int<32)
{
inMonth2Int=31;
break;
}
else
badInput=true;
case 'd':
if(inDay2Int>0&&inDay2Int<31)
{
inMonth2Int=30;
break;
}
else
badInput=true;
case 'e':
if(inDay2Int>0&&inDay2Int<32)
{
inMonth2Int=31;
break;
}
else
badInput=true;
case 'f':
if(inDay2Int>0&&inDay2Int<31)
{
inMonth2Int=30;
break;
}
else
badInput=true;
case 'g':
if(inDay2Int>0&&inDay2Int<32)
{
inMonth2Int=31;
break;
}
else
badInput=true;
case 'h':
if(inDay2Int>0&&inDay2Int<32)
{
inMonth2Int=31;
break;
}
else
badInput=true;
case 'i':
if(inDay2Int>0&&inDay2Int)
{
inMonth2Int=30;
break;
}
else
badInput=true;
case 'j':
if(inDay2Int>0&&inDay2Int<32)
{
inMonth2Int=31;
break;
}
else
badInput=true;
case 'k':
if(inDay2Int>0&&inDay2Int<31)
{
inMonth2Int=30;
break;
}
else
badInput=true;
case 'l':
if(inDay2Int>0&&inDay2Int<32)
{
inMonth2Int=31;
break;
}
else
badInput=true;
badInput=true;
}
if (inEra1!="AD"&&inEra1!="BC")
badInput=true;
if (inEra1=="AD")
{
in1=(inYear1Int*365.24219)+inDay1Int+inMonth1Int;
}
if (inEra1=="BC")
{
in1=(inYear1Int*365.24219)+inDay1Int+inMonth1Int*(0-1);
}
}
}
return 0;
}