Thread: question about time conversion

  1. #1
    Registered User
    Join Date
    Oct 2010

    question about time conversion

    I was wondering if someone could tell me what is wrong with this code. I am trying to write a program which will ask the user to enter a time and then add 12 to it if the end char entered is P and the numerical value of the hour is < 12. With the following code, the program adds 12 regardless and I am trying to figure out how to resolve this. Thanks.

    cout << "Enter start time (hh:mm A/P): ";
    float start_hour = 0;
    float start_minute = 0;
    char A = 0;
    char P = 0; 
    char dummy(0);
    cin >> start_hour >> dummy >> start_minute >> A || P;
    if ( P && start_hour <12 );
    	                          start_hour = start_hour + 12;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    What's A || P supposed to mean?

    What's the ; at the end of the if statement do?

    The answer to both is "not what you're expecting"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. boost posix time question
    By l2u in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 01:31 PM
  3. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 04:44 AM
  4. It's a question of time ...
    By Mandy_C in forum C Programming
    Replies: 4
    Last Post: 04-09-2006, 02:18 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM