Unexpected output in c++ code , Not getting expected result -
i made program show possible time in clock if angle given between hour , minute hand ..
#include <iostream> #include <fstream> #include <string> #include <vector> #include <math.h> using namespace std; int main(){ //ifstream cin("input.txt"); vector <float> hour , min , angle; string str; int h , m ; float diff, cal1 ,cal2 , , j;; h = 11 ; m = 59; ( = 0 ; <= h ; i++ ){ ( j = 0 ; j <= m ; j = j + 1){ cal1 = (i*60/2) + (j/2); // hour angle cal2 = (j*6); // min angle; diff = fabs(cal1 - cal2) ; if ( diff > 180 ){ diff = 360.0000 - diff ; } //cout << cal1 << " " << cal2 << " " << diff << endl; hour.push_back(i); min.push_back(int(j)); angle.push_back(diff); } } int t , value , size; cin >> t; size = hour.size(); while( t-- ){ cin >> value; ( int = 0 ; < size;i++ ){ //cout << angle[i] << endl; if ( value == angle[i] ){ if ( hour[i] > 9 && min[i] > 9 ){ cout << hour[i] <<":" << min[i] << endl; } else if ( hour[i] <= 9 && min[i] > 9 ){ cout << "0" << hour[i] <<":" << min[i] << endl; } else if ( hour[i] > 9 && min[i] <= 9 ){ cout << hour[i] <<":" << "0" << min[i] << endl; } else { cout << "0" << hour[i] <<":" << "0" << min[i] << endl; } } } } }
for reson when puts input :
2 60.0000 30.0000
i gets
02:00 10:00 00:00
but should
02:00 10:00 01:00 11:00
and when enter input
2 30.0000 60.0000
i gets
01:00 11:00 00.00
when remove 0 in input , gives intergers shows correct answer floats gives wrong answer . ran code in ideone . gave same problem .
value has data type int
input demands float
:
try replacing int value
float value
Comments
Post a Comment