+ 2

Can any1 telI me?want to find time in minute and based on that which is nearest hospital?I got int o/p. But o/p time is in float

#include <iostream> using namespace std; int main() { int dis1,dis2,spd1,spd2,s1,s2,s3,s4,s5,s6; float t1,t2; cin>>dis1>>spd1>>s1>>s2>>s3>>dis2>>spd2>>s4>>s5>>s6; t1=(((dis1*60)/spd1) + ((s1+s2+s3)/60)); t2=(((dis2*60)/spd2) + ((s4+s5+s6)/60)); cout<<t1<<endl<<t2<<endl; if(t1<t2) { cout<<"Hospital 1 is near"; } else if(t1==t2) { cout<<"Both hospitals are near"; } else { cout<<"Hospital 2 is near"; } return 0; }

5th Jul 2017, 10:37 AM
Priyadharshini N
Priyadharshini N - avatar
1 Réponse
+ 7
You will need to convert your ints to floats during your caculations. See Code for example: https://code.sololearn.com/c9L1PUiiBl8L/?ref=app Also to make it easier for your user, try to have prompts for each input.
5th Jul 2017, 11:36 AM
jay
jay - avatar