question about time conversion

This is a discussion on question about time conversion within the C++ Programming forums, part of the General Programming Boards category; I was wondering if someone could tell me what is wrong with this code. I am trying to write a ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    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.

    Code:
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 12:31 PM
  3. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 03: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

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