Need advice

This is a discussion on Need advice within the C++ Programming forums, part of the General Programming Boards category; I am writing a function that will take time as three integer arguments (for hours,minutes, and seconds), and returns the ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    12

    Question Need advice

    I am writing a function that will take time as three integer arguments (for hours,minutes, and seconds), and returns the number of seconds since the last time the clock "struck 12". I will then use this function to calculate the amount of time in seconds between two times, both of which are within on 12-hour cycle of the clock. I am getting error messages like crazy. Any advice would be appreciated.

    #include <iostream>

    using namespace std;


    int get_sec(int, int, int); //function prototype

    int main()

    {
    int hh, mm, ss;


    cout << "Enter Hour, Minutes, and Seconds: " << endl;
    cin >> hh >> mm >> ss;


    cout <<"Seconds Since 12: "<< get_sec(hh,mm,ss) <<endl;

    int hh1, mm1, ss1;
    cout <<"Enter First Time Hour, Minute, and Second: " <<get_sec(hh,mm,ss)<<endl;

    cin >> hh1 >> mm1 >> ss1;

    int hh2,mm2, ss2;

    cout <<"Enter Second Time Hour, Minute, and Second:"<<get_sec(hh,mm,ss)<<endl;
    cin>> hh2 >> mm2 >> ss2>>

    int d;
    d = get_sec(hh1, mm1, ss1) -get_sec(hh2, mm2, ss2);

    cout << "Difference between two times: " <<="0)";

    }
    sec; return min; + hr="hr" sec="sec" ; 60 * min="min"; { sec)

    int min, hr, (int get_sec 0; <<d<< ? times: two between ?Difference << cout -1; d="d" (d if>


    return 0;

    }


    The error messages that I am getting are:

    error C2062: type 'int' unexpected
    error C2065: 'd' : undeclared identifier
    error C2676: binary '<<=' : 'class std::basic_ostream<char,struct std::char_traits<char> >' does not define this operator or a conversion to a type acceptable to
    the predefined operator
    warning C4508: 'main' : function should return a value; 'void' return type assumed
    error C2501: 'sec' : missing storage-class or type specifiers
    error C2143: syntax error : missing ';' before 'return'
    error C2143: syntax error : missing ';' before '+'
    error C2143: syntax error : missing ';' before 'constant'
    error C2447: missing function header (old-style formal list?)

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    the code tags > you

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    12
    I do not understand your post. Please explain

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    <code> </code>
    replace the < with [ and replace the > with ]
    and put ur code inbetween to preserve formatting.

  5. #5
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Code:
    cin>> hh2 >> mm2 >> ss2>> 
    
    int d;
    should be

    Code:
    cin>> hh2 >> mm2 >> ss2; 
    
    int d;
    Code:
    cout << "Difference between two times: " <<="0)";
    ain't gonna work. Don't know what you want from it but the problem is <<="0)"; get rid of the '=' and you will get rid of the error but as I say, I don't know if it will give you what you actually want.

    Then your compiler is having a barney here

    Code:
    }
    sec; return min; + hr="hr" sec="sec" ; 60 * min="min"; { sec) 
    
    int min, hr, (int get_sec 0; <<d<< ? times: two between ?Difference << cout -1; d="d" (d if>
    and rightly so. The '}' finishes your main () function and everything else is just hanging in free space. You need to re-think the position and number of parentheses. Not to mention that I can't make head nor tail of the last 2 lines of that code. I don't mean to be rude but it's meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advice on C Programming with MSVC++ 2008
    By IT_Guy in forum Windows Programming
    Replies: 1
    Last Post: 03-06-2009, 03:23 AM
  2. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 02:46 PM
  3. Resume advice
    By Zughiaq in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-15-2005, 02:16 PM
  4. girl friend advice (prob. the wrong place)
    By B0bDole in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2004, 06:38 PM
  5. Partitioning advice?
    By mart_man00 in forum Tech Board
    Replies: 6
    Last Post: 01-10-2003, 09:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21