+ 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; }

22nd Jun 2021, 5:09 PM
Shruti Shukla
Shruti Shukla - avatar
5 Antworten
- 1
Input=3:45:45pm
22nd Jun 2021, 5:17 PM
Shruti Shukla
Shruti Shukla - avatar
+ 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.
22nd Jun 2021, 5:21 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
What input you are trying .. ? It may not matching any if condition.
22nd Jun 2021, 5:16 PM
Jayakrishna 🇮🇳
22nd Jun 2021, 5:17 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 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.
22nd Jun 2021, 5:27 PM
Jayakrishna 🇮🇳