Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
C++
int main(){
    int i;
    char a[11];
    for(i=0;i<10;i++)
        cin>>a[i];
    if(a[8]=='a' || a[8]=='A')
    {
        for(i=0;i<=7;i++)
            cout<<a[i];
    }
    else if((a[8]=='P' || a[8]==P) && (a[0]==0) && (a[1]==1 || a[1]=='2' || a[1]=='3' || a[1]=='4' || a[1]=='5' || a[1]=='7' || a[1]==7))
    {
        a[1]=a[1]+2;
        a[0]='1';
        cout<<a;
    }
    else if(a[0]=='0'&& (a[1]=='8'|| a[1]=='9'))
    {
        a[0]='2';
        if(a[1]=='8')
            a[1]='0';
        else
            a[1]='1';
        cout<<a;
    }
    else if(a[0]=='1' &&(a[1]=='0'|| a[1]=='1'))
    {
        a[0]='2';
        if(a[1]==0)
            a[1]=='2';
        else
            a[1]='3';
        cout<<a;
    }        
    else if(a[0]=='1' && a[1]=='2' && (a[8]=='a' || a[8]=='A'))
    {
        cout<<"00:00:00";
        
    }
    else
    {
        cout<<"19:05:n45";
    }
    return 0;
}


What I have tried:

I'm not getting what's wrong in my code? Any help would be appreciated.
Posted
Updated 12-Sep-18 4:22am
v2

 
Share this answer
 
C++
struct tm tm = {0};
char s[20]; 

tm.tm_year = ...;
tm.tm_mon = ...;
tm.tm_mday = ...;

strftime(s, 20, "%F %H:%M:%S", &tm);
 
Share this answer
 
Looks like a muddleheadedness:

> Like 6pm will be 18.

C++
// else if((a[8]=='P' || a[8]==P) && (a[0]==0) && (a[1]==1 || a[1]=='2' || a[1]=='3' || a[1]=='4' || a[1]=='5' || a[1]=='7' || a[1]==7))

 else if((a[8]=='P' || a[8]==P) && (a[0]==0) && (a[1]==1 || a[1]=='2' || a[1]=='3' || a[1]=='4' || a[1]=='5' || a[1]=='6' || a[1]=='7'))
 
Share this answer
 
v2
Your string operations are very confusing and should be slow. You better use the std::string class with its nice functions like for input.

If something in your code is unclear you should set a break point and use the debugger.

tips:
a) use identions for better readability
b) you better write some comments in your code to make it better understandable.
c) overwriting input data is not a good idea, generate a output string.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900