Results 1 to 7 of 7

Thread: Newbie needs local function help!

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    New England USA
    Posts
    13

    Angry

    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

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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; 
    }
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    New England USA
    Posts
    13
    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.

  4. #4
    Lively Member
    Join Date
    Sep 2000
    Location
    Singapore
    Posts
    78
    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...

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    New England USA
    Posts
    13
    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

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  7. #7
    New Member
    Join Date
    Oct 2000
    Location
    Bottom Shelf of the Refridgerator Behind left over peas
    Posts
    1

    Talking

    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
  •  



Click Here to Expand Forum to Full Width