PDA

View Full Version : C++ - The program won't run


MrBandwagon
April 17th, 2007, 11:20 PM
I can't get this to run after compiling it. Weird thing is, when I compile it it doesn't find any errors, but when I try to run it, it pops an error message. This is the code:

#include <iostream>

void input_dates(int&, int&, int&);
int leap_year(int);
int ammount_of_days(int, int, int, int, int, int);
int mm_zero_daycount(int,int);
int yearperyear_daycount(int,int);

int main()
{

using std::cout;
using std::cin;
using std::endl;

int dd1, mm1, yyyy1, dd2, mm2, yyyy2;

cout<<"Enter two dates (dd/mm/yyy)\n";

cout<<"For the first date: \n";

input_dates(dd1, mm1, yyyy1);

cout<<"For the second date: \n";
input_dates(dd2, mm2, yyyy2);

cout<<"The ammount of days between both dates is: "<<ammount_of_days(dd1, mm1, yyyy1, dd2, mm2, yyyy2)<<endl;






return 0;

}

void input_dates(int &dd, int &mm, int &yyyy)
{
using std::cout;
using std::cin;

char opt;
int sel;

cout<<"Enter de day:";
cin>>dd;



while(dd<=0&&dd>31)
{
cout<<"Day number is invalid, please enter a valid day number:";
cin>>dd;

}//endwhile

cout<<"Enter the month:";
cin>>mm;

while(mm<1&&mm>12)
{
cout<<"Month numer is invalid, please enter a valid month number:";
cin>>mm;
}//endwhile

cout<<"Enter the year:";
cin>>yyyy;

while((mm==4||mm==9||mm==11&&dd>30)||(mm==2&&dd>28&&leap_year(yyyy)==0)||(mm==2&&dd>29&&leap_year(yyyy)==1)){

cout<<"The day/month/year combination is invalid.\n";
do
{
cout<<"Please choose whether to change:\n";
cout<<"1. Change the day\n";
cout<<"2. Change the month\n";
cout<<"3. Change the year\n";
cout<<"After making your selection, press 'y' if you wish to change another thing.\n";
cout<<"Make your selection now: ";
cin>>sel;

while(sel<1||sel>3)
{
cout<<"Invalid selection, please make a valid selection: ";
cin>>sel;
}//end while

switch(sel){
case 1:

cout<<"Enter the day:";
cin>>dd;

while(dd<=0&&dd>31)
{
cout<<"Day number is invalid, please enter a valid day number:";
cin>>dd;

}//endwhile

break;
case 2:

cout<<"Enter the month:";
cin>>mm;
while(mm<1&&mm>12)
{
cout<<"Month numer is invalid, please enter a valid month number:";
cin>>mm;
}//endwhile
break;
case 3:

cout<<"Enter the year: ";
cin>>yyyy;

break;

}//endswitch

cout<<"Would you like to make another selection? (y make another, press another key to exit)";
cin>>opt;




}while(opt=='y');

}//endwhile

}//endindput_dates

int leap_year(int yyyy)
{
if(yyyy%4==0&&yyyy%400==0)
return 1;
else
return 0;



}//end leap_year func

int amount_of_days(int dd1, int mm1, int yyyy1, int dd2, int mm2, int yyyy2)
{

int final_daycount;

final_daycount=mm_zero_daycount(mm1-1, yyyy1)+mm_zero_daycount(mm2-1, yyyy2)+yearperyear_daycount(yyyy1, yyyy2)+dd1+dd2;

return final_daycount;


}//end amount of days

int mm_zero_daycount(int mm, int yyyy)
{
int i, daycount;

for(i=mm; i>0; i--)
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
daycount+=31;
else
if(i==4||i==6||i==9||i==11)
daycount+=30;
else
if(i==2&&leap_year(yyyy)==1)
daycount+=29;
else
if(i==2&&leap_year(yyyy)==0)
daycount+=28;


}//endfor

return daycount;


}//end mm zero daycount

int yearperyear_daycount(int yyyy1, int yyyy2)
{
int daycount, year_track, dif_year;
daycount=0;
year_track=yyyy1;

if(yyyy1>yyyy2)
dif_year=yyyy1-yyyy2;
else
if(yyyy1<yyyy2)
dif_year=yyyy2-yyyy1;

while(dif_year>0)
{
if(leap_year(year_track)==1)
daycount+=366;
else
daycount+=365;

year_track=year_track+1;
dif_year--;
}//endwhile

return daycount;
}//end year per year daycount

The error message when I try to run it is this:

--------------------Configuration: Melvin_Beltran_project1 - Win32 Debug--------------------
Linking...
Melvin_Beltran_project1.obj : error LNK2001: unresolved external symbol "int __cdecl ammount_of_days(int,int,int,int,int,int)" (?ammount_of_days@@YAHHHHHHH@Z)
Debug/Melvin_Beltran_project1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Melvin_Beltran_project1.exe - 2 error(s), 0 warning(s)

I don't know if it's relevant but I'm compiling it in Microsoft Visual C++ 6.0. Also sorry for the lack of documentation but it's due tomorrow and I finished the code earlier today, haven't gotten around to documenting yet.