+ 1
Why it's not printing any output ???
#include <iostream> using namespace std; int main() { int hour,min,sec,z=12; string a,b,c; string d="am",e="pm"; int f=24; cin>>hour>>a>>min>>b>>sec>>c; int arr[12]; for(int i=0;i<12;i++){ arr[i]=z; ++z; } if(hour<=12){ if(c==d){ cout<<hour<<a<<min<<b<<sec<<c; } else if(c==e){ cout<<arr[hour]<<a<<min<<b<<sec<<c; } } else{ if(c==d){ cout<<hour<<a<<min<<b<<sec<<c; } else if(c==e){ cout<<(12-(arr[f-hour]))<<a<<min<<b<<sec<<c; } } return 0; }
5 Réponses
- 1
Input=3:45:45pm
+ 2
because a takes a string.
So when you take the input ,the value of a becomes:
:45:45pm
So the other values aren't initialized.
+ 1
What input you are trying .. ? It may not matching any if condition.
+ 1
Please follow this:
https://www.sololearn.com/post/75089/?ref=app
+ 1
3 will be reading into hour, after that entire input is of type string will be reading into a.
Remainings having garbage values....
Use char instead of string for single char input(char a,b); For only 'c' take it as string. then it works.
but it needs some more corrections, hope you can find it easily.