Simplifying a program

Hello everyone, I am new here and would like to ask for some advice. Like many of you I am currently taking a C++ class at my college. I will not ask you to solve any homework problems for me, but I would like some help.

I have a program that I just got done writing, but it is too long and messy. I was wondering if you could give me tips on how to simplify it. It works as it is(with the values I have tested) so I can at least say that it runs.

Code:
int main(){
int month,cday,inday,wday,ihrs,imins,isecs,whrs,wmins,wsecs,fday,fhrs,fmins,fsecs,fmonth,oday;
cout<<"Enter current month: ";
cin>>month;
cout<<"What day of current month is it? ";
cin>>inday;
cout << "Please enter current hour: ";
cin >> ihrs;
cout << "Please enter current minute: ";
cin >> imins;
cout << "Please enter current second: ";
cin >> isecs;
cout<<"Please enter the number of days you wish to travel back: ";
cin>>wday;
cout << "Enter how many hours you want to travel back: ";
cin >> whrs;
cout << "Enter how many minutes you want to travel back: ";
cin >> wmins;
cout << "Enter how many seconds you want to travel back: ";
cin >> wsecs;

//Calculations begin.//


if(month==1){
cday=inday;
}
if(month==2){
cday=31+inday;
}
if(month==3){
cday=59+inday;
}
if(month==4){
cday=90+inday;
}
if(month==5){
cday=120+inday;
}
if(month==6){
cday=151+inday;
}
if(month==7){
cday=182+inday;
}
if(month==8){
cday=213+inday;
}
if(month==9){
cday=244+inday;
}
if(month==10){
cday=274+inday;
}
if(month==11){
cday=305+inday;
}
if(month==12){
cday=335+inday;
}


fday=cday-wday;
if(fday<0){
cout<<"ERROR: the amount of days you entered exceeds the number of days in the year";
}
else{

fhrs = ihrs - whrs;
if (fhrs < 0)
{
cout << "ERROR: the amount of hours you entered exceeds the number of hours in a day. \n";
}
else
{
fmins = imins - wmins;
if (fmins < 0) {
fhrs = (fhrs - 1);
fmins = (60 + fmins);
}
fsecs = isecs - wsecs;
if (fsecs < 0) {
fmins = (fmins - 1);
fsecs = (60 + fsecs);
}

}
}



if(fday<32){
fmonth=1;
oday=fday;
}
else if(fday<60){
fmonth=2;
oday=fday-31;
}
else if(fday<91){
fmonth=3;
oday=fday-59;
}
else if(fday<121){
fmonth=4;
oday=fday-90;
}
else if(fday<152){
fmonth=5;
oday=fday-120;
}
else if(fday<183){
fmonth=6;
oday=fday-151;
}
else if(fday<214){
fmonth=7;
oday=fday-182;
}
else if(fday<245){
fmonth=8;
oday=fday-213;
}
else if(fday<275){
fmonth=9;
oday=fday-244;
}
else if(fday<306){
fmonth=10;
oday=fday-274;
}
else if(fday<336){
fmonth=11;
oday=fday-305;
}
else if(fday<366){
fmonth=12;
oday=fday-335;
}

cout << "When you arrive,it will be: " << fmonth <<"/" <<oday <<"th " << fhrs << ":" << fmins << ":" << fsecs;
return 0;
}
Use an array to store the days in each month, then replace the code with a simple loop.
Ok I will give that a try. Thank you!
For your month if's: use a switch.

http://www.cplusplus.com/doc/tutorial/control/
Topic archived. No new replies allowed.