PDA

Click to See Complete Forum and Search --> : Newbie needs local function help!


Colora
Oct 28th, 2000, 06:50 PM
I'll post the whole code, otherwise you won't see where the function setup begins. I'm getting error C2601: 'calSeconds' : local function definitions are illegal.

Here 'tis:

//E2_26.cpp exercise 3.26
//create a stopwatch type program

#include <iostream>

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

int calSeconds (int, int, int);

int main ()
{
int hour=0, min=0, sec=0, time1, time2, endtime;

cout<<"Enter a time, between 12:00 AM and 11:59:59 PM."<<endl;
cout<<"Use a space between hours, minutes, and seconds."<<endl;

cin>>hour>>min>>sec;

time1=calSeconds(hour,min,sec);

cout<<time1<<" seconds in total pass between 12:00 AM and the time you picked."<<endl;

cout<<"Enter a second time, to find the seconds occur between both times entered."<<endl;

cin>>hour>>min>>sec;

time2=calSeconds(hour,min,sec);

if (time1>time2)
endtime = time1 - time2;
else
endtime = time2 - time1;

cout<<endtime<<" seconds occur between the two times entered."<<endl;

int calSeconds (int x, int y, int z)
{
int t1 = 0;
t1 = ( (x*60*60) + (y* (60+z) ) );
return t1;
}
return 0;
}

Someone let me know what is so illegal about my local function definitions please? I'm thoroughly stuck on this.

Thanks, Colora

Vlatko
Oct 28th, 2000, 07:03 PM
Why did you put the function definition in the main()function. This is how your code shoul look.
This code works fine.


//E2_26.cpp exercise 3.26
//create a stopwatch type program

#include <iostream>

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

int calSeconds (int, int, int);

int main ()
{
int hour=0, min=0, sec=0, time1, time2, endtime;

cout<<"Enter a time, between 12:00 AM and 11:59:59 PM."<<endl;
cout<<"Use a space between hours, minutes, and seconds."<<endl;

cin>>hour>>min>>sec;

time1=calSeconds(hour,min,sec);

cout<<time1<<" seconds in total pass between 12:00 AM and the time you picked."<<endl;

cout<<"Enter a second time, to find the seconds occur between both times entered."<<endl;

cin>>hour>>min>>sec;

time2=calSeconds(hour,min,sec);

if (time1>time2)
endtime = time1 - time2;
else
endtime = time2 - time1;

cout<<endtime<<" seconds occur between the two times entered."<<endl;


return 0;
}

int calSeconds (int x, int y, int z)
{
int t1 = 0;
t1 = ( (x*60*60) + (y* (60+z) ) );
return t1;
}

Colora
Oct 28th, 2000, 07:11 PM
Well that solved the compile error...now if you could tell me what these link errors mean, it would be great!

LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/E3_26.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Blitz
Oct 29th, 2000, 10:03 AM
Originally posted by Colora
Well that solved the compile error...now if you could tell me what these link errors mean, it would be great!

LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/E3_26.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Are you running Visual C++?

Try deleting the .exe in the DEBUG folder and restart Visual C++.

Hope this helps...

Colora
Oct 29th, 2000, 10:22 AM
Actually I ended up getting a copy of TurboC Lite from someone, and with a few minor tweaks it ended up working perfectly!

But that's good to know about deleting those bug .exe files, since I can't stand the TurboC setup and much prefer the ease of use with the MS version.

I now direct your attention to the other thread I started just a little while ago, about factorial of "e." If one could get on their knees and beg, that would be me right now.

Help!

Colora

parksie
Oct 30th, 2000, 02:08 PM
You should have used a Console project.

Kana Beer
Oct 30th, 2000, 09:28 PM
Don't forget the parenths which multiply Y * (60 + Z )