0

Fever (int, double, float)

Write a program that takes body temperature in Celsius as input. If it is in range from 36.1 to 36.9 (not inclusive) print "OK", otherwise print “Not OK”. Sample Input 37.2 Sample Output Not OK https://code.sololearn.com/c4aSAa8A6ViN/?ref=app // What am I missing here??

3rd Mar 2021, 2:17 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
13 Respuestas
+ 6
There are lots of problems with your c++ code. Here is a corrected version: #include <iostream> using namespace std; int main() { //your code goes here float temp; cin >> temp; if (temp >=36.1 && temp <36.9) { cout << "OK" << endl; } else { cout << "Not OK"; } return 0; } Here is the original version with the fixes commented: #include <iostream> using namespace std; int main() { float temp; cin >> temp; if (float temp >=36.1 && <=36.9); // remove the "float" and temp must be added for comparison with 36.9. // remove the semicolons after the if-statement's condition { cout << "OK" << endl; else "Not OK"; // you need to cout the "Not OK" string. // You also need to end the if-statement's block before starting the else block. } return 0; }
3rd Mar 2021, 2:20 AM
Josh Greig
Josh Greig - avatar
+ 3
Tahiti🍷 1 - How else inside if block 2 - why there is Semicolon after if condition 3 - why there is not cout in else part 4 - why there is float temp in if part You need to think about above points. if (float temp >=36.1 && <=36.9); { cout << "OK" << endl; else "Not OK"; } If program says print "Not ok" it means you have to use cout to print value. so it would be cout << "Not ok";
3rd Mar 2021, 3:36 AM
A͢J
A͢J - avatar
+ 2
#include <iostream> using namespace std; int main() { //your code goes here float temp; cin >> temp; if (temp >=36.1 && temp <36.9) { cout << "OK" << endl; } else { cout << "Not OK"; } return 0; } Good Luck
25th Jan 2022, 4:32 PM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
+ 1
Josh Greig , I can’t believe I didn’t notice all those errors. Thanks for your assistance. I’ll try this again!
3rd Mar 2021, 2:38 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
+ 1
I Am AJ ! - Thank you for those pointers. I’m surely learning a lot from all these errors.
3rd Mar 2021, 5:17 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
+ 1
//NOT OK relpace--->Not OK #include <iostream> using namespace std; int main() { //your code goes here float celsius; cin>>celsius; if(celsius>=36.1 && celsius<=36.9) cout<<"OK"; else cout<<"Not OK"; }
13th Oct 2021, 9:13 PM
Hasan Ali
Hasan Ali - avatar
+ 1
#include <iostream> using namespace std; int main() { //your code goes here double temperature; cin>>temperature; if(temperature>=36.0 && temperature<=36.9) { cout<<"OK"<<endl; } else{ cout<<"Not OK"<<endl; } }
27th Apr 2022, 1:37 PM
Okoh Samson Eromosele
0
Tahiti🍷 why should you be followed huh? Show your skills then ask about followers !!
12th Jun 2021, 1:34 PM
Sujuma
Sujuma - avatar
0
//Try this my long version. #include <iostream> using namespace std; int main() { double celciusDeg[9] = {36.1, 36.2, 36.3, 36.4, 36.5, 36.6, 36.7, 36.8, 36.9}; double userDeg; cin>>userDeg; if(userDeg == celciusDeg[0]){ cout<<"OK"; } if(userDeg == celciusDeg[1]){ cout<<"OK"; } if(userDeg == celciusDeg[2]){ cout<<"OK"; } if(userDeg == celciusDeg[3]){ cout<<"OK"; } if(userDeg == celciusDeg[4]){ cout<<"OK"; } if(userDeg == celciusDeg[5]){ cout<<"OK"; } if(userDeg == celciusDeg[6]){ cout<<"OK"; } if(userDeg == celciusDeg[7]){ cout<<"OK"; } if(userDeg == celciusDeg[8]){ cout<<"OK"; } if(userDeg>=37.0) { cout<<"Not OK"; } if(userDeg<=36.0){ cout<<"Not OK"; } return 0; }
2nd Aug 2021, 3:34 AM
Joseph
Joseph - avatar
0
Joseph, if the input was 36.15, the requirements say to print "OK" but your code will print nothing. Comparing for equality with float or double also needs to be done with floating point error in mind. Some numbers that look clean and simple in base 10 end up impossible to perfectly represent as floating-points so the == operator returns false unexpectedly.
2nd Aug 2021, 5:15 AM
Josh Greig
Josh Greig - avatar
0
I hope you understand my code! #include <iostream> using namespace std; int main() { float x; // x= temperature in celsius. cin >> x; if (x>36.1 && x<36.9) {cout << "Ok" << endl;} else {cout << "Not Ok" << endl;} }
24th Sep 2021, 9:41 AM
sai akshagn
sai akshagn - avatar
0
#include <iostream> using namespace std; int main() { //your code goes here float temp; cin >> temp; if (temp >=36.1 && temp <36.9) { cout << "OK" << endl; } else { cout << "Not OK"; } return 0; }
3rd Jan 2023, 1:29 AM
ZARIF JORAYEV
ZARIF JORAYEV - avatar
- 2
Tahiti🍷 bro follow me. I am a beginner
3rd Mar 2021, 3:12 AM
Hyperjones
Hyperjones - avatar