|
-
Oct 28th, 2000, 06:50 PM
#1
Thread Starter
New Member
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
-
Oct 28th, 2000, 07:03 PM
#2
Frenzied Member
Why did you put the function definition in the main()function. This is how your code shoul look.
This code works fine.
Code:
//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;
}
-
Oct 28th, 2000, 07:11 PM
#3
Thread Starter
New Member
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.
-
Oct 29th, 2000, 11:03 AM
#4
Lively Member
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...
-
Oct 29th, 2000, 11:22 AM
#5
Thread Starter
New Member
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
-
Oct 30th, 2000, 03:08 PM
#6
Monday Morning Lunatic
You should have used a Console project.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 30th, 2000, 10:28 PM
#7
New Member
Don't forget the parenths which multiply Y * (60 + Z )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|