0

Whats wrong with this code?

#include <iostream> using namespace std; int main() { int c,f; cout<<" Type in a temperature in °F: "<<endl<<endl; cin>>f>>endl; c=5/9*(f-32); cout<<f<<"°F="<<c<<"°C"<<endl; return 0; }

25th Nov 2018, 10:50 PM
Wiktor Karkoszka
Wiktor Karkoszka - avatar
3 Réponses
+ 2
Three things. 1.) No 'endl' in the line with 'cin'; 2.) the ints should be doubles, so that you get precise results; 3.) most tricky: 5/9 -> 0, because both are integers. Write either 5.0/9 or 5/9.0 instead!
26th Nov 2018, 1:00 AM
HonFu
HonFu - avatar
+ 1
Thank you guys, now everything works properly :)
26th Nov 2018, 3:26 PM
Wiktor Karkoszka
Wiktor Karkoszka - avatar
0
Does it throw an error? I would change c from int to double tho and I will not use endl incon althou I do not know if that is something you can call wrong
25th Nov 2018, 11:08 PM
Paul